我有一个Web服务,其中包含我希望由Spring Framework .NET注入的属性。没有错误消息,但没有注入。我做错了什么?
以下是我对xml文件的内容:
<object type="MyCompany.MyProject.Business.MyClass">
<property name="PaymentService" ref="PaymentService" />
</object>
以下是我对代码的看法:
namespace MyCompany.MyProject.Web
{
public class MyService : WebService
{
public IPaymentService PaymentService { get; set; }
}
}
答案 0 :(得分:0)
这是我最终做的事情。我们必须有一个应用程序上下文:
IPaymentService paymentService = (IPaymentService) SecurityHelper.GetAppContext().GetObject("PaymentService");
public static IApplicationContext GetAppContext()
{
if (WebApplicationContext.Current == null) throw new Exception("Spring not initialized");
IApplicationContext context = WebApplicationContext.Current;
if (context == null) throw new Exception("Spring context not initialized");
return context;
}