you can use Forwarding to register an implementation to more than one
interface.
if you need control over individual components while registering "all
types"
Kernel.Register(AllTypes
.FormAssembly(assembly)
.BaseOn<IAutoRegisteredService>()
.Configure(c => c.Lifestyle.Transient)
.ConfigureFor<MainModuleCommands>(c =>
c.Forward<IModuleCommand>())
.WithService.FromInterface());
if you need more control than this I would configure the edge cases
explicitly and then auto-register the remaining components
Kernel
.Register(Component
.For<IAutoRegisteredService, IModuleCommand>()
.ImplementedBy<MainModuleCommand>()
.Lifestyle.Singleton)
.Register(AllTypes
.FormAssembly(assembly)
.BaseOn<IAutoRegisteredService>()
.Unless(t => Kernel.HasComponent(t))
.Configure(c => c.Lifestyle.Transient)
.WithService.FromInterface());
those are 2 thoughts approaches to solving the problem.
On Nov 22, 10:19 am, "Lundberg, Per" <[email protected]> wrote:
> Hi guys,
>
> I'm currently running into a fairly interesting issue here. My code looks
> like this:
>
> windsorContainer.Register(AllTypes.FromAssembly(assembly)
>
> .BasedOn<IAutoRegisteredService>()
> .WithService
> .FromInterface());
>
> This is pretty nice; it gives me a very easy way to declaratively (without
> manual C# code) register my services in the Windsor Container.
>
> However, there is one slight problem I've run into now: there is an
> interface called IModuleCommands which implements this interface
> (IAutoRegisteredService). Then, my application modules have their own child
> interfaces deriving from this interface, like IMainModuleCommands.
>
> So we have:
>
> IModuleCommands
>
> |
>
> IMainModuleCommands
>
> |
>
> MainModuleCommands (the implementing class)
>
> All fair and square. The problem is just that this Register() call above
> will only set the MainModuleCommands class up as a component providing the
> IMainModuleCommands service. But the problem is that I have an abstract
> base class (OverlayViewModelBase ) that doesn't know about the
> IMainModuleCommands; it only knows about (and needs) the IModuleCommands
> interface.
>
> So, how do I change the above Register() line to register this component as
> providing more than one service?
>
> Then of course, there is the very interesting challenge I'm facing related
> to the scope. If I would have multiple modules, each having a separate
> implementor of IModuleCommands, we would definitely run into trouble (which
> IModuleCommands implementer should the IoC container chose? How would it
> know?).
>
> This class (IModuleCommands) is being referred to by the
> OverlayViewModelBase class. The nice part about Castle Windsor is that it
> gives me property injection, so I can inject an IModuleCommands instance
> into the base class without the awkward & ugly "base(moduleCommands)"
> syntax. However, this problem kind of defeats that benefit... J
>
> Best regards,
>
> Per
--
You received this message because you are subscribed to the Google Groups
"Castle Project Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/castle-project-users?hl=en.