开发者

Calling a method on an injected property (from an ASPX page)

开发者 https://www.devze.com 2023-04-01 13:04 出处:网络
I\'m teaching myself Spring.NET and to see if I\'ve got everything wired up properly, I\'m trying to call a method on an object that I have tried to inject into an ASPX page (I know this isn\'t probab

I'm teaching myself Spring.NET and to see if I've got everything wired up properly, I'm trying to call a method on an object that I have tried to inject into an ASPX page (I know this isn't probably best practice)

This is in my aspx file (so I'm trying to call the 'orderDescription' getter on the orderService property of this aspx page)

[some html here]
<%= OrderService.orderDescription() %>
[some more html here]

In my Web.config, I've got this in my 'spring, objects' section

开发者_运维技巧
  <object type="Default.aspx">
    <property name="OrderService" ref="orderService"/>
  </object>

When I run it, it tells me that I need an object instance before I can call a static method, i.e. it thinks I'm trying to call 'orderDescription' as a static method on OrderService. But Spring is supposed to have injected 'OrderService' as a property of my aspx page, so why can't I call it this way.

I know I'm missing something simple but I can't figure it out. Appreciate any tips

Thanks


Here's a summary of what you need to do to get this working. Originally I was going to say that "Default.aspx" wasn't the name of a class, but I guess spring.net must translate that for you. Did you put the SpringPageHandler configuration in your web.config? Also, do you actually have a property named OrderService defined on the class and of the appropriate type? I would expect that if you did, then you would actually get a NullReferenceException (another small note, you said OrderService.orderDescription() is trying to call the getter on the orderDescription property - but you put parenthesis like it is a method call (if it is just a property it should just be OrderService.orderDescription [no parenthesis])).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号