/// <summary>
 /// CTOR.
 /// </summary>
 /// <param name="name"></param>
 /// <param name="pattern"></param>
 /// <param name="allowReassign"></param>
 public InjectingAttribute(string name        = "", CreationPattern pattern = CreationPattern.CreateOnGet,
                           bool allowReassign = false)
 {
     AllowReassign = allowReassign;
     Name          = name;
     Pattern       = pattern;
 }
Ejemplo n.º 2
0
        public void Register(string name, Type type, CreationPattern pattern = CreationPattern.CreateOnGet,
                             bool reassign = false)
        {
            if (!reassign && (mNamedInstances.ContainsKey(name) || mNamedFabriques.ContainsKey(name)))
            {
                throw new TypeAlreadyRegisteredException(name);
            }

            Register(type, obj => mNamedInstances.Add(name, obj), () => mNamedFabriques.Add(name, () => CreateObject(type)),
                     pattern);
            mLogger?.Trace($"Type '{type}' with name '{name}' registered with pattern {pattern}.");
        }
Ejemplo n.º 3
0
        public void Register <TDep>(CreationPattern pattern = CreationPattern.CreateOnGet, bool reassign = false)
            where TDep : class
        {
            var type = typeof(TDep);

            if (!reassign && (mInstances.ContainsKey(type) || mFabriques.ContainsKey(type)))
            {
                throw new TypeAlreadyRegisteredException(type);
            }

            Type t = typeof(TDep);

            if (t.GetConstructors().Length > 1)
            {
                throw new IncorrectContructorException(t, "Type has more than one constructor.");
            }

            Register(t, obj =>
            {
                if (mInstances.ContainsKey(type))
                {
                    mInstances[type] = obj;
                }
                else
                {
                    mInstances.Add(type, obj);
                }
            }, () =>
            {
                if (mFabriques.ContainsKey(type))
                {
                    mFabriques[type] = CreateObject <TDep>;
                }
                else
                {
                    mFabriques.Add(type, CreateObject <TDep>);
                }
            },
                     pattern);

            mLogger?.Trace($"Type '{type.AssemblyQualifiedName}' registered with pattern '{pattern}'.");
        }
 /// <summary>
 /// Constructor.
 /// </summary>
 public BuildComponentEntry(BuildComponentType type, BuildComponentFactoryDelegate factory, CreationPattern pattern)
 {
     this.ComponentType = type;
     _factory = factory;
     this.Pattern = pattern;
 }
 /// <summary>
 /// Adds a factory.
 /// </summary>
 /// <param name="componentType">The type which is created by this factory.</param>
 /// <param name="factory">Delegate which is responsible for creating the Component.</param>
 /// <param name="creationPattern">Creation pattern.</param>
 public void AddFactory(BuildComponentType componentType, BuildComponentFactoryDelegate factory, CreationPattern creationPattern)
 {
     _componentEntriesByType[componentType] = new BuildComponentEntry(componentType, factory, creationPattern);
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Constructor.
 /// </summary>
 public BuildComponentEntry(BuildComponentType type, BuildComponentFactoryDelegate factory, CreationPattern pattern)
 {
     ComponentType = type;
     _factory      = factory;
     Pattern       = pattern;
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Adds a factory.
 /// </summary>
 /// <param name="componentType">The type which is created by this factory.</param>
 /// <param name="factory">Delegate which is responsible for creating the Component.</param>
 /// <param name="creationPattern">Creation pattern.</param>
 public void AddFactory(BuildComponentType componentType, BuildComponentFactoryDelegate factory, CreationPattern creationPattern)
 {
     _componentEntriesByType[componentType] = new BuildComponentEntry(componentType, factory, creationPattern);
 }
Ejemplo n.º 8
0
        private void Register(Type t, Action <Lazy <object> > adding, Action createFabrique, CreationPattern pattern)
        {
            if (t.GetConstructors().Length > 1)
            {
                throw new IncorrectContructorException(t, "Type has more than one constructor.");
            }

            if (pattern == CreationPattern.CreateOnGet)
            {
                createFabrique();
            }
            else
            {
                Lazy <object> objInit;
                if (pattern == CreationPattern.SingleImmediatly)
                {
                    var obj = CreateObject(t);
                    objInit = new Lazy <object>(() => obj);
                }
                else
                {
                    objInit = new Lazy <object>(() => CreateObject(t));
                }
                adding(objInit);
            }
        }