WithServiceSelf should have done the trick.

The container has a nice debugger view - could you check what it shows
to you? just hit a breakpoint where the container instance is
accessible/in-the-scope, and see what is in there...

On Thu, May 28, 2015 at 11:17 PM, bdaniel7 <bdani...@gmail.com> wrote:
> 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 IViewWindow
> public 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 used
> Container.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.



-- 
Cheers,
hammett
http://www.d-collab.com/
http://www.hammettblog.com/

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