//public static T Instance<T>() where T : class //{ // Func<Type, bool> func = null; // if (!UnityContainerExtensions.IsRegistered<T>(IFactory.iunityContainer_0)) // { // bool flag = false; // try // { // object obj; // Monitor.Enter(obj = IFactory.object_0, ref flag); // Assembly assembly = typeof(T).Assembly; // Class2 @class = Class2.smethod_0(assembly); // if (@class.method_0() != null) // { // foreach (ContainerRegistration current in @class.method_0().Registrations) // { // if (!UnityContainerExtensions.IsRegistered(IFactory.iunityContainer_0, current.RegisteredType)) // { // UnityContainerExtensions.RegisterType(IFactory.iunityContainer_0, current.RegisteredType, current.MappedToType, new InjectionMember[0]); // } // } // } // string bllSuffix = ".BLL"; // IEnumerable<Type> arg_DB_0 = assembly.GetTypes(); // if (func == null) // { // func = new Func<Type, bool>(IFactory.smethod_0<T>); // } // IEnumerable<Type> enumerable = from type in arg_DB_0.Where(func) // where type.BaseType != null && type.BaseType.IsGenericType && !type.IsInterface && typeof(T).IsAssignableFrom(type) && type.Namespace.EndsWith(bllSuffix) // select type; // foreach (Type current2 in enumerable) // { // UnityContainerExtensions.RegisterType(IFactory.iunityContainer_0, typeof(T), current2, new InjectionMember[0]); // } // } // finally // { // if (flag) // { // object obj=0; // Monitor.Exit(obj); // } // } // } // return UnityContainerExtensions.Resolve<T>(IFactory.iunityContainer_0, new ResolverOverride[0]); // Func<Type, bool> predicate = null; // if (!iunityContainer_0.IsRegistered<T>()) // { // lock (object_0) // { // Assembly assembly = typeof(T).Assembly; // Class2 class3 = Class2.smethod_0(assembly); // if (class3.method_0() != null) // { // foreach (ContainerRegistration registration in class3.method_0().Registrations) // { // if (!UnityContainerExtensions.IsRegistered(iunityContainer_0, registration.RegisteredType)) // { // UnityContainerExtensions.RegisterType(iunityContainer_0, registration.RegisteredType, registration.MappedToType, new InjectionMember[0]); // } // } // } // string bllSuffix = ".BLL"; // if (predicate == null) // { // predicate = new Func<Type, bool>(IFactory.smethod_0<T>); // } // foreach (Type type in from type in assembly.GetTypes().Where<Type>(predicate) // where (((type.BaseType != null) && type.BaseType.IsGenericType) && (!type.IsInterface && typeof(T).IsAssignableFrom(type))) && type.Namespace.EndsWith(bllSuffix) // select type) // { // UnityContainerExtensions.RegisterType(iunityContainer_0, typeof(T), type, new InjectionMember[0]); // } // } // } // return iunityContainer_0.Resolve<T>(new ResolverOverride[0]); //} public static T Instance <T>() where T : class { Func <Type, bool> predicate = null; if (!iunityContainer_0.IsRegistered <T>()) { lock (object_0) { Assembly assembly = typeof(T).Assembly; Class2 class3 = Class2.smethod_0(assembly); if (class3.method_0() != null) { foreach (ContainerRegistration registration in class3.method_0().Registrations) { if (!UnityContainerExtensions.IsRegistered(iunityContainer_0, registration.RegisteredType)) { UnityContainerExtensions.RegisterType(iunityContainer_0, registration.RegisteredType, registration.MappedToType, new InjectionMember[0]); } } } string bllSuffix = ".BLL"; if (predicate == null) { predicate = new Func <Type, bool>(IFactory.smethod_0 <T>); } foreach (Type type in from type in assembly.GetTypes().Where <Type>(predicate) where (((type.BaseType != null) && type.BaseType.IsGenericType) && (!type.IsInterface && typeof(T).IsAssignableFrom(type))) && type.Namespace.EndsWith(bllSuffix) select type) { UnityContainerExtensions.RegisterType(iunityContainer_0, typeof(T), type, new InjectionMember[0]); } } } return(iunityContainer_0.Resolve <T>(new ResolverOverride[0])); }
public void RegisterType <F, T>(params object[] members) where T : F { lock (this.container) { UnityContainerExtensions.RegisterType <F, T>(this.container, this.ToObjects <InjectionMember>(members)); } }
public void RegisterType <T>(int lifecycle, params object[] members) { lock (this.container) { UnityContainerExtensions.RegisterType <T>(this.container, this.GetLifetimeManager(lifecycle), this.ToObjects <InjectionMember>(members)); } }
public void RegisterTypeWithConstructor <T>(string name, params object[] constructors) { lock (this.container) { UnityContainerExtensions.RegisterType <T>(this.container, name, this.ToObjects <InjectionConstructor>(constructors)); } }
public void RegisterTypeWithConstructor <T>(string name, int lifecycle, params object[] constructors) { lock (this.container) { UnityContainerExtensions.RegisterType <T>(this.container, name, this.GetLifetimeManager(lifecycle), this.ToObjects <InjectionConstructor>(constructors)); } }
public void RegisterType(Type from, Type to, string name, params object[] members) { lock (this.container) { UnityContainerExtensions.RegisterType(this.container, from, to, name, this.ToObjects <InjectionMember>(members)); } }
public void RegisterType <F, T>(string name, int lifecycle, params object[] members) where T : F { lock (this.container) { UnityContainerExtensions.RegisterType <F, T>(this.container, name, this.GetLifetimeManager(lifecycle), this.ToObjects <InjectionMember>(members)); } }
private PolicyDefinition UpdateRuleDrivenPolicyInjection() { UnityContainerExtensions.RegisterType <InjectionPolicy, RuleDrivenPolicy>(_extension.Container, _policyName, new InjectionConstructor(_policyName, new ResolvedArrayParameter <IMatchingRule>(_rulesParameters.ToArray()), _handlersNames.ToArray())); return(this); }
public static void RegisterTypes(IUnityContainer container) { InjectionConstructor injectionConstructor = new InjectionConstructor(new object[1] { (object)ConfigurationManager.ConnectionStrings["YmatouStaticContentConnectionString"].ConnectionString }); if (null == HttpContext.Current) { UnityContainerExtensions.RegisterType <StaticContentQueryDataContext, StaticContentQueryDataContext>(container, (LifetimeManager) new ContainerControlledLifetimeManager(), new InjectionMember[1] { (InjectionMember)injectionConstructor }); } else { UnityContainerExtensions.RegisterType <StaticContentQueryDataContext, StaticContentQueryDataContext>(container, (LifetimeManager) new HttpContextLifetimeManager <StaticContentQueryDataContext>(), new InjectionMember[1] { (InjectionMember)injectionConstructor }); } UnityContainerExtensions.RegisterType <IStaticContentQueryService, StaticContentQueryService>(container, new InjectionMember[0]); }
private void RegistrarMapeamento(Mapeamento mapeamento, bool sobreescrever) { if (string.IsNullOrEmpty(mapeamento.Nome)) { if (!sobreescrever && UnityContainerExtensions.IsRegistered(this._container, mapeamento.De)) { throw new Exception($"Já existe registro de mapeamento para este tipo ( {mapeamento.De.FullName} ), verifique o tipo ou faça o registro explicitando um nome."); } InjectionMember[] memberArray1 = new InjectionMember[] { new Interceptor <InterfaceInterceptor>(), new InterceptionBehavior <PolicyInjectionBehavior>() }; UnityContainerExtensions.RegisterType(this._container, mapeamento.De, mapeamento.Para, memberArray1); } else { if (!sobreescrever && UnityContainerExtensions.IsRegistered(this._container, mapeamento.De)) { throw new Exception($"Já existe registro de mapeamento nomeado para este tipo ( {mapeamento.De.FullName} ), verifique o tipo."); } InjectionMember[] memberArray2 = new InjectionMember[] { new Interceptor <InterfaceInterceptor>(), new InterceptionBehavior <PolicyInjectionBehavior>() }; UnityContainerExtensions.RegisterType(this._container, mapeamento.De, mapeamento.Para, mapeamento.Nome, memberArray2); } }
private void RegisterMapping(Mapping mapping, bool writeOver) { if (string.IsNullOrEmpty(mapping.Name)) { if (!writeOver && UnityContainerExtensions.IsRegistered(this._container, mapping.From)) { throw new Exception($"Já existe registro de mapeamento para este tipo ( {mapping.From.FullName} ), verifique o tipo ou faça o registro explicitando um nome."); } InjectionMember[] injectionMembers = new InjectionMember[] { new Interceptor <InterfaceInterceptor>(), new InterceptionBehavior <PolicyInjectionBehavior>() }; UnityContainerExtensions.RegisterType(this._container, mapping.From, mapping.To, injectionMembers); } else { if (!writeOver && UnityContainerExtensions.IsRegistered(this._container, mapping.From)) { throw new Exception($"Já existe registro de mapeamento nomeado para este tipo ( {mapping.From.FullName} ), verifique o tipo."); } InjectionMember[] injectionMembers = new InjectionMember[] { new Interceptor <InterfaceInterceptor>(), new InterceptionBehavior <PolicyInjectionBehavior>() }; UnityContainerExtensions.RegisterType(this._container, mapping.From, mapping.To, mapping.Name, injectionMembers); } }
private static void smethod_1(IUnityContainer iunityContainer_1, Assembly assembly_0) { Dictionary <string, Type> dictionary = new Dictionary <string, Type>(); Dictionary <string, Type> dictionary2 = new Dictionary <string, Type>(); string value = ".DAL"; string value2 = ".IDAL"; Type[] types = assembly_0.GetTypes(); for (int i = 0; i < types.Length; i++) { Type type = types[i]; string @namespace = type.Namespace; if (!string.IsNullOrEmpty(@namespace)) { if (type.IsInterface && @namespace.EndsWith(value2)) { if (!dictionary.ContainsKey(type.FullName)) { dictionary.Add(type.FullName, type); } } else if (@namespace.EndsWith(value) && !dictionary2.ContainsKey(type.FullName)) { dictionary2.Add(type.FullName, type); } } } foreach (string current in dictionary.Keys) { Type type2 = dictionary[current]; foreach (string current2 in dictionary2.Keys) { Type type3 = dictionary2[current2]; if (type2.IsAssignableFrom(type3)) { UnityContainerExtensions.RegisterType(iunityContainer_1, type2, type3, new InjectionMember[0]); } } } }
/// <summary> /// 注册抽象类型与具体实现的类型 /// </summary> /// <param name="from">接口类型</param> /// <param name="to">具体类型</param> public void RegisterType(Type from, Type to) { UnityContainerExtensions.RegisterType(this, from, to); }
public void RegisterTypes(IUnityContainer container) { UnityContainerExtensions.RegisterType <IDatabaseConnectionService, DatabaseConnectionService>(container, new ContainerControlledLifetimeManager()); }