Question

I was wondering if there is some best practice to achive the functionality I need.

I have a web application that during startup, with reflection, scans certain assemblies (plugins) and registers their dependencies against common kernel.

The external libraries may need same dependencies.

For example library A gets scanned and its dependecy D1 is registered. Then library B is scanned and tries to register same dependency - D1 - against kernel again. Castle obviously will complain if I try to register same component twice.

My question is: How you usually handle the scenario when you simply want to skip the component that is already registered. Is there some extension method on IWindsorContainer that performs this task?

Thanks in advance.

Était-ce utile?

La solution

You could use inside your register statement:

Component.For<Test>.OnlyNewServices()

or when registering multiple components at once:

Types.FromAssemblyContaining<Test>().InSameNamespaceAs<Test>().Configure(c => c.OnlyNewServices());

Or a variation that suits you. See this link for conditional registration: http://docs.castleproject.org/Windsor.Conditional-component-registration.ashx

Autres conseils

If you are sure that all your dependencies (services) will be only in those plugin assemblies, you can just go ahead and register every service (I assume you know which types should exactly be registered, i.e. you have them somehow marked) from every plugin assembly. You don't have to resolve any dependencies manually as this will be handled by the container itself, so you don't have to worry about ordering or double registration issues.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top