gpt4 book ai didi

c# - CaSTLe Windsor 重建实例

转载 作者:太空宇宙 更新时间:2023-11-03 15:47:22 24 4
gpt4 key购买 nike

我试图在每次 WCF 调用后处理我所有的业务逻辑服务,并试图通过使用 windsor 来实现它(Ninject 只是没有工作),我有一个以下容器类:

    public class LDSWindsorContainer : WindsorContainer
{
public LDSWindsorContainer()
{
AddFacility<WcfFacility>().
Register(
Component.For<IDomainService>().ImplementedBy<DomainService>().LifeStyle.PerWcfOperation(),
Component.For<IChangeLogService>().ImplementedBy<ChangeLogService>().LifeStyle.PerWcfOperation(),
Component.For<ILogService>().ImplementedBy<LogService>().LifeStyle.PerWcfOperation(),
Component.For<ICentreInformationService>()
.ImplementedBy<CentreInformationService>()
.LifeStyle.PerWcfOperation().OnCreate(x=>Debug.WriteLine("Created")),
Component.For<ICentreService>().ImplementedBy<CentreService>().LifeStyle.PerWcfOperation(),
Component.For<ITimeZoneService>().ImplementedBy<TimeZoneService>().LifeStyle.PerWcfOperation(),
Component.For<IBrandService>().ImplementedBy<BrandService>().LifeStyle.PerWcfOperation(),
Component.For<IPricingService>().ImplementedBy<PricingService>().LifeStyle.PerWcfOperation(),
Component.For<IDirectoryService>()
.ImplementedBy<DirectoryService>().LifestyleSingleton());
}
}

除了 IDirectoryService 及其实现之外的所有对象都是我的业务逻辑服务,最后一个是 WCF 服务本身,我有以下 Application_Start() 方法:

         public class Global : System.Web.HttpApplication
{

protected void Application_Start(object sender, EventArgs e)
{
var container = new LDSWindsorContainer();
...
}
}

我的服务的构造函数如下所示:

            private ILogService Logger { get; set; }
private IDomainService DomainService { get; set; }
private ICentreInformationService CentreInformationService { get; set; }
private ICentreService CentreService { get; set; }
private ITimeZoneService TimeZoneService { get; set; }
private IBrandService BrandService { get; set; }
private IPricingService PricingService { get; set; }

public DirectoryService(IBrandService brandService, ITimeZoneService timeZoneService, ICentreService centreService, ICentreInformationService centreInformationService, IDomainService domainService, ILogService logger, IPricingService pricingService)
{
BrandService = brandService;
TimeZoneService = timeZoneService;
CentreService = centreService;
CentreInformationService = centreInformationService;
DomainService = domainService;
Logger = logger;
PricingService = pricingService;
}

我的 DirectoryService.svc 和 Web.config 中也有相应的行 -

Factory="Castle.Facilities.WcfIntegration.DefaultServiceHostFactory, Castle.Facilities.WcfIntegration    

 <system.webServer>
<modules runAllManagedModulesForAllRequests="true" >
<add name="PerRequestLifestyle" type="Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule, Castle.Windsor" />
</modules>
</system.webServer>

到目前为止,问题是:我的实例被解决了一次(对于第一次调用),工作正常,在调用结束时被处理并且没有为所有即将到来的调用重新实例化,所以基本上我只是得到一个处理处置对象的异常(exception)情况,非常感谢任何想法,提前致谢。

最佳答案

好吧,经过一番努力,我在这里找到了一个完美的答案 -

我的容器设置:

     AddFacility<TypedFactoryFacility>().Register(Component.For<IDomainService>().ImplementedBy<DomainService().LifeStyle.PerWcfOperation(),

AddFacility<WcfFacility>().Register(Component.For<IDirectoryService>().ImplementedBy<DirectoryService>().LifestyleSingleton());

其中 IDomainService 是我想在每次请求后处理的业务逻辑服务,而 IDirectoryService 是我的 WCF 服务。

我的服务工程师

    public DirectoryService(Func<IDomainService> domainService)
{
DomainServiceFactory = domainService;
}

和一些糖来避免所有调用重命名:

    private Func<IDomainService> DomainServiceFactory { get; set; }

private IDomainService DomainService
{
get { return DomainServiceFactory(); }
}

关于c# - CaSTLe Windsor 重建实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27559517/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com