I'm reposting from 
here 
http://stackoverflow.com/questions/30510942/multiple-registrations-with-castle-windsor

I have the following situation in a WPF application:

public class ExpenseView : UserControl, IAccountingView {}
// just a marker, the contract is in IViewWindowpublic interface 
IAccountingView : IViewWindow {}

And I need to be able to register ExpenseView to be resolvable in two ways, 
as concrete type, ExpenseView and as IAccountingView (and maybe as another 
interface as well).

I'm registering the types like this:

// I need a collection of IViewWindow to be usedContainer.Register( 
Classes.FromAssemblyInDirectory( myTypes )
    .BasedOn<IViewWindow>()
    .WithServiceFromInterface()
    .LifestyleTransient()
    );
// all other types don't have interfaces, are used as concrete 
types.Container.Register( Classes.FromAssemblyInDirectory( myTypes )
    .Where( type => type.IsPublic )
    .WithServiceSelf()
    .LifestyleTransient()
    );

Now, this works, ExpenseView and all other types are instantiated, except 
that when I need to use

var newInstance = container.Resolve( iView.ViewType );

to get another instance, where iView.ViewType is the concrete type 
ExpenseView (as per the example), I get this exception:

'Castle.MicroKernel.ComponentNotFoundException'  No component for supporting 
the service ExpenseView was found.

Any ideas why is this happening and how to make it work?

Thank you,

Daniel

-- 
You received this message because you are subscribed to the Google Groups 
"Castle Project Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to castle-project-users+unsubscr...@googlegroups.com.
To post to this group, send email to castle-project-users@googlegroups.com.
Visit this group at http://groups.google.com/group/castle-project-users.
For more options, visit https://groups.google.com/d/optout.

Reply via email to