Wassim AZIRAR Wassim AZIRAR - 1 year ago 103
C# Question

Inject constructor parameters using Unity

Suppose I have an interface called

, and its implemntation
, like this :

public class Blabla : IBlabla
Blabla(string endPoint) { }

Using StructureMap, I can easily inject a parameter to my constructor arguments, like this :

For<IBlabla>().Singleton().Use(() => new Blabla("myBinding"));

How can I acheive this using

I have already tried all this :

container.RegisterType<IBlabla>(new HierarchicalLifetimeManager(), new InjectionFactory((x, t, c) => new Blabla("myBinding")));
container.RegisterType<IBlabla, Blabla>(new InjectionConstructor(new ResolvedParameter<string>("myBinding")));

But none of them worked for me.

Answer Source
container.RegisterType<IBlabla, Blabla>(new InjectionConstructor("myBinding"));