我的网络层(s#arp架构)中有一个soap web服务,它使用这样的服务:
public ReportWebService(IReportService ReportService)
{
Check.Require(ReportService != null, "ReportService may not be null");
this.ReportService = ReportService;
}
有人可以提醒我如何/在哪里配置IReportService的实施注入?
感谢。
基督教
答案 0 :(得分:1)
简短的回答是:只需将ReportService放入yourProject.ApplicationServices,它就会被注入。
答案很长:在Global.asax的yourProject.Web中,您将找到方法InitializeServiceLocator()。这将调用ComponentRegistrar上的静态方法AddComponents。
ComponentRegistrar位于yourProject.web / CastleWindsor中。在那里你会找到
public static void AddComponentsTo(IWindsorContainer container)
{
AddGenericRepositoriesTo(container);
AddCustomRepositoriesTo(container);
AddApplicationServicesTo(container);
container.AddComponent("validator",
typeof(IValidator), typeof(Validator));
}
如果查看AddApplicationServicesTo,您可以看到它是在您的Project.ApplicationServices(.WithService.FirstInterface())中注册所有类型的:
private static void AddApplicationServicesTo(IWindsorContainer container)
{
container.Register(
AllTypes.Pick()
.FromAssemblyNamed("NewittsStore.ApplicationServices")
.WithService.FirstInterface());
}
答案 1 :(得分:0)
这是来自ComponentRegistrar.cs:
/// <summary>
/// The add application services to.
/// </summary>
/// <param name="container">
/// The container.
/// </param>
private static void AddApplicationServicesTo(IWindsorContainer container)
{
container.Register(AllTypes.Pick().FromAssemblyNamed("MyAssembly.ApplicationServices").WithService.FirstInterface());
}
这里来自服务
private readonly IDocumentManagementService _client;
public DocumentService(IDocumentManagementService client)
{
_client = client;
}
这应该会帮助你。