public class Foo { public Foo(string bar) { // Resolve dependency based on 'bar' parameter } } var builder = new ContainerBuilder(); builder.RegisterType(); var container = builder.Build(); var foo = container.Resolve (new NamedParameter("bar", "value"));
public interface IBar { } public class Bar1 : IBar { } public class Bar2 : IBar { } public class Baz { public IBar Bar { get; set; } public Baz(IBar bar) { Bar = bar; } } var builder = new ContainerBuilder(); builder.RegisterTypeIn this example, the Bar property of the Baz class is resolved differently depending on the type passed into the constructor, which is determined by accessing the Type collection of the Target property of the ResolutionContext.().Keyed (typeof(Bar1)); builder.RegisterType ().Keyed (typeof(Bar2)); builder.RegisterType (); var container = builder.Build(); var baz1 = container.Resolve (new TypedParameter(typeof(IBar), container.ResolveKeyed (typeof(Bar1)))); var baz2 = container.Resolve (new TypedParameter(typeof(IBar), container.ResolveKeyed (typeof(Bar2))));