view raw
Wassim AZIRAR Wassim AZIRAR - 5 months ago 56
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.

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