Example #1
0
        private object InvokeMethod(Type impType, Type cType, object command)
        {
            var dep = dependencies.Find(x => x.Implementation == impType);

            if (dep.Behaviour == DIBehaviour.Singleton)
            {
                var methodInfo = FindCommandMethod.Find(impType, cType, dependencies);
                if (methodInfo == null)
                {
                    throw new CantFindMethod(cType.FullName, impType.FullName);
                }
                object obj = methodInfo.Invoke(dep.CurrentObj, new object[] { command });
                return(obj);
            }
            else
            {
                var workObj = CreateObj.Go(dependencies, impType);
                dep.CurrentObj = workObj;
                var methodInfo = FindCommandMethod.Find(impType, cType, dependencies);
                if (methodInfo == null)
                {
                    throw new CantFindMethod(cType.FullName, impType.FullName);
                }
                object obj = methodInfo.Invoke(dep.CurrentObj, new object[] { command });
                return(obj);
            }
        }
Example #2
0
 public void Init()
 {
     for (int i = 0; i < dependencies.Count; i++)
     {
         if (dependencies[i].CurrentObj == null)
         {
             CreateObj.Go(dependencies, dependencies[i].Implementation);
         }
     }
 }
Example #3
0
        public object GetService(Type serviceType)
        {
            IDependency dependency;

            if (serviceType.IsInterface)
            {
                dependency = dependencies.Find(x => x.Interface == serviceType);
            }
            else
            {
                dependency = dependencies.Find(x => x.Implementation == serviceType);
            }
            if (dependency == null)
            {
                throw new CantFindThisDependency(serviceType.FullName);
            }
            var obj = CreateObj.Go(dependencies, dependency.Implementation);

            return(obj);
        }
Example #4
0
        public TResponse GetService <TResponse>()
        {
            IDependency dependency;
            var         serviceType = typeof(TResponse);

            if (serviceType.IsInterface)
            {
                dependency = dependencies.Find(x => x.Interface == serviceType);
            }
            else
            {
                dependency = dependencies.Find(x => x.Implementation == serviceType);
            }
            if (dependency == null)
            {
                throw new CantFindThisDependency(typeof(TResponse).FullName);
            }
            var obj = (TResponse)CreateObj.Go(dependencies, dependency.Implementation);

            return(obj);
        }