public bool TryWrap(Instance instance, out Instance wrapped) { if (instance.ServiceType == typeof(TService)) { var decorator = new ConstructorInstance(typeof(TService), typeof(TDecorator), instance.Lifetime); decorator.AddInline(instance); wrapped = decorator; return(true); } else { wrapped = null; return(false); } }
public void shoule_get_instance_with_inline_dependencies() { ListInstance <string> instance = new ListInstance <string>(typeof(IList <string>)); instance.AddInline(new ObjectInstance(typeof(string), "a")); instance.AddInline(new ObjectInstance(typeof(string), "b")); ConstructorInstance @object = new ConstructorInstance(typeof(ITestInstance), typeof(TestInstance), ServiceLifetime.Transient); @object.AddInline(instance); IContainer container = new Container(p => { p.For <ITestInstance>().Use(@object); }); ITestInstance value = container.GetInstance <ITestInstance>(); value.Data.ShouldHaveTheSameElementsAs(new string[] { "a", "b" }); }