WPFプロジェクトで最新のCastleWindsorを使用していますが、非常に奇妙な問題が発生しました。
私のViewModelの1つを解決するとき-コンテナはサービスとして必要とされないタイプを自己登録し、それらのタイプの空のプロパティを注入します、コンテナがそれ自体でサービスを自己登録することは一般的な動作ですか?
コンテナーの構成後にカーネルのサービスコレクションを確認すると、1つの解決の直前に停止し、解決が終了した後にさらに3つのサービスが追加されたことがわかります...
誰かがこの問題に光を当てることができれば、それは本当に役に立ちますありがとう
私の設定ファイル:
public IContainerService Get()
{
var container = new WindsorContainer();
var adapter = new ContainerServiceWindsorAdapter(container.Kernel);
container.Register(Component.For<IWindowManager>().ImplementedBy<TelerikWindowManager>());
container.Register(Component.For<IEventAggregator>().ImplementedBy<EventAggregator>());
container.Register(Component.For<INavigationService>().ImplementedBy<NavigationService>());
container.Register(Component.For<IFileService>().ImplementedBy<FileService>());
container.Register(Component.For<ISessionFactory>().UsingFactoryMethod(k =>
{
var fs = container.Resolve<IFileService>();
var normalConfig = new Configuration().Configure(Path.Combine(fs.GetWorkingFolder(), CONFIG_FILE));
return Fluently.Configure(normalConfig)
.CurrentSessionContext<ThreadStaticSessionContext>()
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<NHDataAccessProvider>())
.ExposeConfiguration(BuildSchema)
.BuildSessionFactory();
}));
container.Register(Component.For<IDataAccessProvider>().ImplementedBy<NHDataAccessProvider>());
//Register IShell
container.Register(Component.For<IShell>().ImplementedBy<ShellViewModel>()
.Properties(p => p.PropertyType != typeof(IModuleDataScreen)));
//Register all IModuleDataScreens
container.Register(AllTypes.FromAssemblyContaining<ShellViewModel>()
.BasedOn(typeof(IModuleDataScreen))
.WithService.FromInterface(typeof(IModuleDataScreen))
.Configure(x => x.LifeStyle.Is(LifestyleType.Transient))
.Configure(x => x.Named(x.Implementation.Name)));
//Register all Modules
container.Register(AllTypes.FromAssemblyContaining<ShellViewModel>()
.BasedOn(typeof(IModule))
.WithService.FromInterface(typeof(IModule))
.Configure(x => x.LifeStyle.Is(LifestyleType.Singleton))
.Configure(x => x.Named(x.Implementation.Name)));
container.Install(new CommonComponentsInstaller(),new DynamicCalculationsInstaller());
var sf = container.Resolve<ISessionFactory>();
CurrentSessionContext.Bind(sf.OpenSession());
return adapter;
}
public class DynamicCalculationsInstaller : IWindsorInstaller
{
public void Install(Castle.Windsor.IWindsorContainer container, Castle.MicroKernel.SubSystems.Configuration.IConfigurationStore store)
{
container.Register(Component.For<IFormulaEvaluator>().ImplementedBy<FleeFormulaEvaluator>().LifeStyle.Singleton);
container.Register(Component.For<IRulesEvaluator>().ImplementedBy<FleeRulesEvaluator>().LifeStyle.Singleton);
container.Register(Component.For<IPlansModule>()
.ImplementedBy<PlansModule>()
.LifeStyle
.Transient);
container.Register(
Component.For<IDataProvider<PackageData>>()
.ImplementedBy<PackageDataProvider>()
.LifeStyle
.Transient);
container.Register(Component.For<IPackagesModule>()
.ImplementedBy<PackagesModule>()
.LifeStyle
.Transient);
container.Register(Component.For<ExternalRuleSetService>());
}
}
public class CommonComponentsInstaller : IWindsorInstaller
{
#region Implementation of IWindsorInstaller
public void Install(IWindsorContainer container, IConfigurationStore store)
{
container.Register(Component.For<IErrorHandler>().ImplementedBy<ErrorHandlerEntLibAdapter>());
container.Register(Component.For<ICacheService>().ImplementedBy<CacheServiceEntLibAdapter>());
container.Register(Component.For<ILogger>().ImplementedBy<LoggerEntLibAdapter>());
container.Register(Component.For<IMessageSerializer>().ImplementedBy<MessageSerializer>());
container.Register(Component.For<IInteroperableSerializer>().ImplementedBy<InteroperableSerializer>());
container.Register(Component.For<ILazyComponentLoader>().ImplementedBy<ConcreteClassComponentLoader>().Named("concreteClass"));
}
#endregion
}