public ExpressionInjectorFactoryBenchmark() { _injectorFactory = new ExpressionInjectorFactory(); _constructorWarriorAndWeapon = typeof(NinjaBarracks).GetConstructor(new[] { typeof(IWarrior), typeof(IWeapon) }); _argumentsWarriorAndWeapon = new object[] { new FootSoldier(), new Sword() }; _injector = _injectorFactory.Create(_constructorWarriorAndWeapon); }
public object ActivateInstance(IContainer container) { ConstructorInjector constructorInjector = container.GetConstructor(this.Type); object instance = constructorInjector.Construct(); container.Inject(instance); return(instance); }
public ConstructorInjectionDirectiveBenchmark() { _zeroArgumentConstructor = typeof(NinjaBarracks).GetConstructor(new Type[0]); _twoArgumentConstructor = typeof(NinjaBarracks).GetConstructor(new[] { typeof(IWarrior), typeof(IWeapon) }); var injectorFactory = new ExpressionInjectorFactory(); _zeroArgumentIinjector = injectorFactory.Create(_zeroArgumentConstructor); _twoArgumentIinjector = injectorFactory.Create(_twoArgumentConstructor); }
public WhenConstructorInjectorIsInvoked() { #if !WINRT constructor = typeof(Samurai).GetConstructor(new[] { typeof(IWeapon) }); #else constructor = typeof(Samurai).GetTypeInfo().DeclaredConstructors.Where( c => !c.IsStatic && c.IsPublic && c.GetParameters().Select(p => p.ParameterType).SequenceEqual(new[] { typeof(IWeapon) })).Single(); #endif injector = injectorFactory.Create(constructor); }
public WhenConstructorInjectorIsInvoked() { #if !WINRT constructor = typeof(Samurai).GetConstructor(new[] { typeof(IWeapon) }); #else constructor = typeof(Samurai).GetTypeInfo().DeclaredConstructors.Where( c => !c.IsStatic && c.IsPublic && c.GetParameters().Select(p => p.ParameterType).SequenceEqual(new[] {typeof(IWeapon)})).Single(); #endif injector = injectorFactory.Create(constructor); }
public void Engage() { // Already instantiated if (context.Instance != null) { return; } // Select a constructor var selector = new ConstructorSelector(); var constructor = selector.Selecter(context); // Throw an exception if no constructor is found if (constructor == null) { throw new TypeResolvingFailedException(Strings.TypeHasNoConstructorToInject); } // resolve the arguments of the constructor var constructorInjector = new ConstructorInjector(constructor, context, ResolveArguments(constructor)); constructorInjector.Inject(); }
public WhenConstructorInjectorIsInvoked() { constructor = typeof(Samurai).GetConstructor(new[] { typeof(IWeapon) }); injector = injectorFactory.Create(constructor); }
/// <summary> /// Initializes a new instance of the <see cref="ConstructorDirective"/> class. /// </summary> /// <param name="constructor">The constructor described by the directive.</param> /// <param name="injector">The injector that will be triggered.</param> public ConstructorDirective(ConstructorInfo constructor, ConstructorInjector injector) : base(constructor, injector) { }
public WhenConstructorInjectorIsInvoked() { this.constructor = typeof(Samurai).GetConstructor(new[] { typeof(IWeapon) }); this.injector = this.injectorFactory.Create(this.constructor); }