views:

196

answers:

2

i have somthing like this

 MyRepository<T> : IRepository<T> {

  public MyRepository(string cs){
   ....

}

so i need to register in winsdor this generic type and give him a parameter

i've been trying to do this like so :

Type t = typeof(IRepository<>);
Type t1 = typeof(Repository<>);
Hashtable props = new Hashtable(); 
props.Add("cs", "myconnstring");
container.AddComponentWithProperties("key1", t, t1, props);

and i get the following error

Can't create component 'key1' as it has dependencies to be satisfied. key1 is waiting for the following dependencies:

Keys (components with specific keys) - cs which was not registered.

+2  A: 

Try this:

container.Register(Component.For(typeof(IRepository<>))
   .ImplementedBy(typeof(MyRepository<>))
   .Parameters(Parameter.ForKey("cs").Eq("myconnstring"));

Check out the fluent registration wiki for more information.

Mauricio Scheffer
thnx man it worked fine, i just put the value of cs inside Eq(value)
Omu
A: 

I ran over the same problem of unresolved dependencies, but to me the proposed solution doesn't seem to cover the issue adaquate. When I use 'AddComponentWithProperties' I do it with the intention to have a concrete instance created which is accessible via a given key (in the problem discription "key1" was used). However, 'Register' doesn't seem to allow for assigning a key to the instance. In my case I'd like to add/register more than one (named!) strategy for the service (-interface) that the clients can choose from by using a key. How could I achieve to add/register multiple instances of a service with c'tor dependencies with a key assigned?

apollo
try posting a question on this site
Omu

related questions