Exemplo n.º 1
0
            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);
            }
Exemplo n.º 2
0
            /// <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>());
            }
Exemplo n.º 3
0
 public Container(Action <ServiceRegistry> configuration) : this(ServiceRegistry.For(configuration))
 {
 }