문제

I am currently registering multiple objects with specific names, I'd like to do it by convention.

Currently works:

container.Register(Component.For<Repository>().Named("Repository1").ImplementedBy<Repository1>());
container.Register(Component.For<Repository>().Named("Repository2").ImplementedBy<Repository2>());

container.Register(
            Component.For<RepositoryFactorySelector, ITypedFactoryComponentSelector>().LifestyleSingleton(),
            Component.For<IRepositoryFactory>().AsFactory(c => c.SelectedWith<RepositoryFactorySelector>()));

I've tried:

container.Register(Classes.FromThisAssembly().BasedOn<Repository>().WithServiceDefaultInterfaces());

But then my custom Factory and DefaultTypedFactoryComponentSelector can't find the component by name?

Requested component named 'Repository2' was not found in the container. Did you forget to register it?

How can I register components using a convention but dynamically named?

도움이 되었습니까?

해결책

On the windsor page about registering components by convention (http://docs.castleproject.org/Windsor.Registering-components-by-conventions.ashx) the following code snippet should help you:

container.Register(
   Classes.FromAssembly(Assembly.GetExecutingAssembly())
      .BasedOn<ICommon>()
      .LifestyleTransient()
      .Configure(component => component.Named(component.Implementation.FullName + "XYZ"))

);

By the way, why don't you change your componentselector to select the correct handler based on implementation type ?

Kind regards, Marwijn.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top