使用Castle Windsor的WCF服务初始化方法

时间:2016-03-10 11:41:11

标签: c# .net wcf dependency-injection castle-windsor

我最近开始使用Castle Windsor作为我的主要DI经理。我有几个WCF服务类需要使用castle的WcfFacility进行实例化。我面临的唯一问题是我需要能够在每个服务类中调用初始化方法,并且在使用AsWcfService方法时,不会调用castle的OnCreate方法。

public void Install(IWindsorContainer container, IConfigurationStore store)
{
    container.AddFacility<WcfFacility>().Register(
                 // Filter Assemblies
                 Classes.FromAssemblyInDirectory(new AssemblyFilter(_managersDirectoryName).FilterByName(filterAssemblyByName))
                        .BasedOn<AManagerBase>() //Filter types in assembly
                        .If(t => _usedManagersTypes.ContainsKey(t.AssemblyQualifiedName)) //filter only the used managers
                        .Configure(comp =>
                        {
                            log.DebugFormat("Technology Installed: {0}", comp.Implementation.AssemblyQualifiedName);
                            comp.Named(comp.Implementation.FullName)
                            .AsWcfService()
                            .OnCreate(manager => initializeManager(manager as AManagerBase));
                        })
            );
}

private void initializeManager(AManagerBase manager)
{
   // This method never gets called
   manager.InitiateManagerResources(_dataManager, _wrapperProvider);
}

正确创建和打开WCF服务,但永远不会调用初始化方法。 我在这里做错了什么或者还有其他方法可以实现吗?

0 个答案:

没有答案