If you try

Component.For<YourComponent>().Named("somethingelse")

It should work.

That said, your composition will still use the first one registered,
unless you rewire things somehow. That's why the xml config "works",
because it's registering stuff before everything else. If you change
the key there (the "id"), then you'll get the expected behavior -- if
I understood your problem correctly.




On Mon, Apr 20, 2015 at 7:09 AM, BhaaL DoesNotUseGplus
<[email protected]> wrote:
> In my application, i use the following Install call:
>
> container.Install(Configuration.FromAppConfig(), FromAssembly.This());
>
>
>
> In the most preferable case, the app.config has an empty configuration
> block, with everything else being done by Installer classes.
> However, one reason why I'd like the app.config in front is that I can
> override whatever the Installer decides...at least thats what I initially
> thought was possible. My use case would be to provide a small assembly
> containing one class containing a bugfix, and configuring it using XML to
> replace the component registered by the installers.
>
> Trigger was this line from the documentation:
>>
>> In Windsor first one wins
>>
>> In Castle, the default implementation for a service is the first
>> registered implementation.[...]
>
>
> Now I actually tried to do this; and was faced with a
> ComponentRegistrationException stating that the component is already
> present.
>
> The component I tried to replace was registered without an explicit name (so
> it uses Type.FullName), but even when providing a Name the Exception is
> raised (obviously, since
> Castle.MicroKernel.SubSystems.Naming.DefaultNamingSubSystem tries
> Dictionary.Add and throws if something happens).
>
> So, the installer basically does this:
>
> container.Register(Component.For<ApplicationNamespace.IService>().ImplementedBy<ApplicationNamespace.ComponentClass>());
>
>
> Even specifying the usual suspects of IsFallback() or explicitly naming the
> services has the same result.
>
> And the XML does this:
>
> <component id="ApplicationNamespace.ComponentClass"
> service="ApplicationNamespace.IService"
> type="ReplacementNamespace.ComponentClass, ReplacementAssembly"/>
>
>
>
> Surprisingly, I can actually do this both from within Code and within XML
> (registering the same service multiple times); but it seems I cannot mix
> those two.
>
> Is there any built-in mechanism to support this scenario, or what would I
> have to do to support this on my own?
>
> --
> 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 [email protected].
> To post to this group, send email to [email protected].
> 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 [email protected].
To post to this group, send email to [email protected].
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