Note that there are some explanatory texts on larger screens.

plurals
  1. POService override when component is based on interface produces There is already a component with that name
    primarykey
    data
    text
    <p>From<a href="http://docs.castleproject.org/Windsor.Registering-components-one-by-one.ashx#Supplying_the_component_for_a_dependency_to_use_Service_override_9" rel="nofollow">here</a> I understand how to specify a component, but what if the component implements an interface that itself is resolved in the container?</p> <p>I use three interfaces: <code>IDBViewerModel</code>, <code>IMembershipModel</code> and <code>IMongoConnection</code>. I wish to resolve <code>IDBViewerModel</code> to <code>DBViewerModel</code> and <code>IMembershipModel</code> to <code>MembershipModel</code>. Easy enough. </p> <p>However, both <code>DBViewerModel</code> and <code>MembershipModel</code> expect <code>IMongoConnection</code> as contructor-injected component - and the two components are NOT the same so I want to use service override.</p> <p>My example is as follows. <code>DBViewerModel : IDBViewerModel</code> and <code>MembershipModel : IMembershipModel,</code> where <code>DBViewerModel</code> and <code>MembershipModel</code> constructors expect an injected component and look something like: </p> <pre><code>DBViewerModel(IMongoConnection uaxDB) MembershipModel(IMongoConnection dataDB) </code></pre> <p>Now I have <code>MongoConnection : IMongoConnection</code> and <code>MongoConnection</code> looks like:</p> <pre><code>public MongoConnection(string DBlocation, string DB) </code></pre> <p>I wish to supply DBlocation and DB parameters differently for injection of a <code>MongoConnection</code> component into <code>DBViewerModel</code> and <code>MembershipModel</code>. So I try:</p> <pre><code> container.Register(Component .For&lt;IDBViewerModel&gt;() .ImplementedBy&lt;DBViewerModel&gt;() .LifeStyle.PerWebRequest); container.Register(Component .For&lt;IMembershipModel&gt;() .ImplementedBy&lt;MembershipModel&gt;() .LifeStyle.PerWebRequest); container.Register( Component.For&lt;IMongoConnection&gt;() .ImplementedBy&lt;MongoConnection&gt;() .Named("myservice.dataDB") .DependsOn(Property.ForKey("DBlocation").Eq(USERmongoURL), Property.ForKey("DB").Eq(USERmongoCollection)) .LifeStyle.PerWebRequest, Component.For&lt;IMongoConnection&gt;() .ImplementedBy&lt;MongoConnection&gt;() .Named("myservice.uaxDB") .DependsOn(Property.ForKey("DBlocation").Eq(UAXmongoURL), Property.ForKey("DB").Eq(UAXmongoCollection)) .LifeStyle.PerWebRequest, Component.For&lt;DBViewerModel&gt;() .ServiceOverrides(ServiceOverride.ForKey("dataDB").Eq("myservice.dataDB")), Component.For&lt;MembershipModel&gt;() .ServiceOverrides(ServiceOverride.ForKey("uaxDB").Eq("myservice.uaxDB")) ); </code></pre> <p>My error message says it all - and yet I don't know how to resolve my dependency chain properly: </p> <blockquote> <p>Component DBViewerModel could not be registered. There is already a component with that name. Did you want to modify the existing component instead? If not, make sure you specify a unique name.</p> </blockquote>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload