public void CanInjectStronglyTypedConstructor() { BuilderBase <BuilderStage> builder = new BuilderBase <BuilderStage>(); builder.Strategies.AddNew <SingletonStrategy>(BuilderStage.PreCreation); builder.Strategies.AddNew <CreationStrategy>(BuilderStage.Creation); builder.Policies.SetDefault <ICreationPolicy>(new DefaultCreationPolicy()); Locator locator = new Locator(); IService service = new Service(); IFoo foo = new Foo(); locator.Add(new DependencyResolutionLocatorKey(typeof(IService), null), service); locator.Add(new DependencyResolutionLocatorKey(typeof(IFoo), null), foo); PolicyList policies = new PolicyList(); policies.Set <ICreationPolicy>(new MockWithCtorDependenciesPolicy(), typeof(MockWithCtorDependencies), null); MockWithCtorDependencies mock = builder.BuildUp <MockWithCtorDependencies>(locator, null, null, policies); Assert.IsNotNull(mock); Assert.AreSame(service, mock.service); Assert.AreSame(foo, mock.foo); }
public override object Invoke(object obj, BindingFlags invokeAttr, Binder binder, object[] parameters, CultureInfo culture) { MockWithCtorDependencies mock = (MockWithCtorDependencies)obj; mock.service = (IService)parameters[0]; mock.foo = (IFoo)parameters[1]; return(obj); }