Esempio n. 1
0
        private void Register(Type Tcontract, Type TImplementation, LifeCycle lifeCycle)
        {
            //Initializing the registered object with the respecting implementation and lifecycle
            RegisteredObject registeredObj = new RegisteredObject {
                Implementation = (TImplementation), LifeCycle = lifeCycle
            };

            //Add the Types to the Types to the dictonary
            registeredObjects.Add(Tcontract, registeredObj);
        }
Esempio n. 2
0
 //Method to resolve the object and check for lifecycle
 private object ResolveObject(RegisteredObject implementationObject)
 {
     if (implementationObject.Instance == null ||
         implementationObject.LifeCycle == LifeCycle.Transient)
     {
         var parameters = ResolveConstructorParameters(implementationObject);
         //Creating instances from parameters
         implementationObject.CreateInstance(parameters.ToArray());
     }
     return(implementationObject.Instance);
 }
Esempio n. 3
0
        //Method to check for non-registered Types
        public object Resolve(Type Tcontract)
        {
            object implementationType;

            if (!registeredObjects.ContainsKey(Tcontract))
            {
                throw new InterfaceNotRegisteredException("The Interface is not registered");
            }

            else
            {   //Getting implementation attributes from specific type
                RegisteredObject implementationObject = registeredObjects[Tcontract];
                implementationType = ResolveObject(implementationObject);
            }

            return(implementationType);
        }