0

我有一个 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; }
    }
}
4

1 回答 1

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;
        }
于 2013-01-24T12:39:01.073 回答