12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Reflection;
- using System.Configuration;
- namespace SCC.Common
- {
-
-
-
- public sealed class IOC
- {
-
-
-
-
-
-
- public static T Resolve<T>(object[] args = null) where T : class
- {
-
- string className = typeof(T).Name.Substring(1);
-
- string fullName = typeof(T).FullName;
- int flag = fullName.IndexOf('`');
-
- if (flag != -1)
- {
- int dot = fullName.LastIndexOf('.', flag);
-
- className = fullName.Substring(dot + 2);
- }
- return DependencyInjector.GetClass<T>(className, args);
- }
- }
-
-
-
- public sealed class DependencyInjector
- {
-
-
-
-
-
-
-
- public static T GetClass<T>(string className, object[] args = null) where T : class
- {
-
- string factoryName = typeof(T).Namespace;
-
- string dllName = ConfigurationManager.AppSettings[factoryName];
-
- string fullClassName = dllName + "." + className + "Services";
-
- object classObject = Assembly.Load(dllName).CreateInstance(fullClassName, true, BindingFlags.Default,null, args, null, null);
- return classObject as T;
- }
- }
- }
|