public ScopedInverseInstanceExpression <TImpl> For <TService>() where TService : class { if (!typeof(TService).IsAssignableFrom(typeof(TImpl))) { throw new ArgumentException($"There is no conversion from {typeof(TImpl).Name} to {typeof(TImpl).Name}"); } AddRootRegistration(); var instanceExpression = _parent.For <TService>(); Instance instance; if (String.IsNullOrEmpty(_name)) { instance = instanceExpression.Use(c => (TService)c.GetInstance(typeof(TImpl))); } else { instance = instanceExpression.Use(c => (TService)c.GetInstance(typeof(TImpl), _name)).Named(_name); } instance.Lifetime = _lifetime; return(this); }
/// <summary> /// Directs StructureMap to always inject dependencies into any and all public Setter properties /// of the type TServiceType. /// </summary> /// <typeparam name="TType"></typeparam> /// <returns></returns> public InstanceExpression <TType> FillAllPropertiesOfType <TType>() where TType : class { Add(new LambdaSetterPolicy(prop => prop.PropertyType == typeof(TType))); return(_parent.For <TType>()); }
public Container(Action <ServiceRegistry> configuration) : this(ServiceRegistry.For(configuration)) { }