Yan34
Yan34

Reputation: 11

cannot convert from collection<Interface> to Microsoft.Practices.unity.injectionmember

I use Dependency Injection et in the config file unity I include

container.RegisterType<ICollection<IModifObserver>>(new Collection<IModifObserver>() { new NotifyHisto() });

but I have error of conversion from cannot convert from collection<IModifObserver> to Microsoft.Practices.unity.injectionmember

I want fill my collection with an instance of object.

Upvotes: 1

Views: 1045

Answers (1)

Yacoub Massad
Yacoub Massad

Reputation: 27871

If you want to register an instance, use the RegisterInstance method like this:

container
    .RegisterInstance<ICollection<IModifObserver>>(
        new Collection<IModifObserver>() { new NotifyHisto() });

If you want the container to return a new instance every time you resolve, then you can use the InjectionFactory class with the RegisterType method like this:

container
    .RegisterType<ICollection<IModifObserver>>(
        new InjectionFactory(
            c => new Collection<IModifObserver>() { new NotifyHisto() }));

Upvotes: 1

Related Questions