Пример #1
0
        public void Register <Tinterface, Timplementation>()
        {
            var myInterface = typeof(Tinterface);
            var myType      = typeof(Timplementation);

            if (!myInterface.IsInterface)
            {
                throw new ArgumentException("Left Type must be interface");
            }

            if (!myInterface.IsAssignableFrom(myType))
            {
                throw new ArgumentException("Right Type must be assignable from left Type");
            }


            var myDefaultConstructor = myType.GetConstructor(Type.EmptyTypes);

            if (myDefaultConstructor == null)
            {
                _myTypes[myInterface] = new ConcreteTypeCreationModel {
                    ConcreteType = myType
                };
            }
            else
            {
                _myTypes[myInterface] = new ConcreteTypeCreationModel {
                    DefaultConstructor = myDefaultConstructor
                };
            }
        }
Пример #2
0
        public void Register <T>(Func <object> objectFactoryFunction)
        {
            var myType = typeof(T);

            _myTypes[myType] = new ConcreteTypeCreationModel {
                CustomCreationFunction = objectFactoryFunction
            };
        }
Пример #3
0
        public void Register <T>()
        {
            var myType = typeof(T);
            var myDefaultConstructor = myType.GetConstructor(Type.EmptyTypes);

            if (myDefaultConstructor == null)
            {
                _myTypes[myType] = new ConcreteTypeCreationModel {
                    ConcreteType = myType
                };
            }
            else
            {
                _myTypes[myType] = new ConcreteTypeCreationModel {
                    DefaultConstructor = myDefaultConstructor
                };
            }
        }
Пример #4
0
        public void Register <Tinterface, Timplementation>(Func <object> objectFactoryFunction)
        {
            var myInterface = typeof(Tinterface);
            var myType      = typeof(Timplementation);

            if (!myInterface.IsInterface)
            {
                throw new ArgumentException("Left Type must be interface");
            }

            if (!myInterface.IsAssignableFrom(myType))
            {
                throw new ArgumentException("Right Type must be assignable from left Type");
            }

            _myTypes[myInterface] = new ConcreteTypeCreationModel {
                CustomCreationFunction = objectFactoryFunction
            };
        }