Hi Jason,

Thanks. I ended up using the .Select() method for specifying the services;
that way, I could just grab up all interfaces (excluding certain ones) and
register them as services in the container.

I prefer to use generic approaches here, since this is an application
framework; individual applications don't have access to do
component-specific tweaking (like below). Instead, this is taken care of by
the framework. That's why I need more generic approaches.

The way I did it now will work, until the applications start to scale up to
a certain size... :-) By then I need to change, or start using child
containers.

Does anyone of you have experience using child containers? Pros cons? You
could take an architectural standpoint and say that "child containers are
bad", but I don't really agree. I've seen cases where we would have
benefitted from that; cases where the inter-component communication became
quite awkward and clumsy because the application was using only one
container instance (and only one Event Aggregator; this was back in the
days while we were using Composite WPF and Unity).

The problem as I see it when you're using child containers is scope: making
certain stuff use a specific container instance... but maybe, it can be
solved somehow.

Best regards,
Per

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Jason Meckley
Sent: den 22 november 2010 19:50
To: Castle Project Users
Subject: Re: FromInterface ponderings...

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.

-- 
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.

Reply via email to