public static void RegisterConfig(this IIocBuilder builder, XElement root) { var compEles = root.Element("components").Elements("component"); foreach (var ele in compEles) { var serviceType = Type.GetType(ele.Attribute("type").Value); var interfaceType = Type.GetType(ele.Attribute("service").Value); LifeTimeScope scope = LifeTimeScope.Transient; if (ele.Attribute("scope") != null) { switch (ele.Attribute("scope").Value.ToLower()) { case "singleton": scope = LifeTimeScope.Singleton; break; case "workunit": scope = LifeTimeScope.WorkUnit; break; case "transiant": default: scope = LifeTimeScope.Transient; break; } } bool autoWire = ele.AttributeValue <bool>("autowire", false); string name = ele.AttributeValue("name", null); Func <IIocContext, IDictionary <string, object> > getConstructorParameters = null; if (ele.HasElements) { var paraEles = ele.Element("parameters").Elements("parameter"); Dictionary <string, object> paras = new Dictionary <string, object>(); foreach (var pele in paraEles) { paras.Add(pele.Attribute("name").Value, pele.Attribute("value").Value); } getConstructorParameters = (ctx) => { return(paras); }; } builder.RegisterType(interfaceType, serviceType, scope, name, autoWire, getConstructorParameters); } var moduleEles = root.Element("modules").Elements("module"); foreach (var ele in moduleEles) { var moduleType = Type.GetType(ele.Attribute("type").Value); IIocModule module = Activator.CreateInstance(moduleType) as IIocModule; builder.RegisterModule(module); } }
public static void RegisterModule(this IIocBuilder builder, IIocModule module) { module.Load(builder); }
public static void RegisterConfig(this IContainerManager containerManager, XElement root) { var compEles = root.Element("components").Elements("component"); foreach (var ele in compEles) { var serviceType = GetTypeByFullName(ele.Attribute("type").Value); var interfaceType = GetTypeByFullName(ele.Attribute("service").Value); ComponentLifeStyle scope = ComponentLifeStyle.Transient; if (ele.Attribute("scope") != null) { switch (ele.Attribute("scope").Value.ToLower()) { case "singleton": scope = ComponentLifeStyle.Singleton; break; case "request": scope = ComponentLifeStyle.InRequestScope; break; case "thread": scope = ComponentLifeStyle.InThreadScope; break; case "transiant": default: scope = ComponentLifeStyle.Transient; break; } } string name = ele.Attribute("name") == null ? null : ele.Attribute("name").Value; if (ele.HasElements) { var paraEles = ele.Element("parameters").Elements("parameter"); var constructors = serviceType.GetConstructors(); foreach (var constructor in constructors) { var parameters = constructor.GetParameters(); List <object> pvals = new List <object>(); try { foreach (var para in parameters) { var pele = paraEles.FirstOrDefault(e => e.Attribute("name").Value.ToLower() == para.Name.ToLower()); object val = null; if (pele != null) { val = ConvertTo(para.ParameterType, pele.Attribute("value").Value); } else { val = containerManager.TryResolve(para.ParameterType); } pvals.Add(val); } object instance = constructor.Invoke(pvals.ToArray()); containerManager.AddComponentInstance(interfaceType, instance, name); } catch { continue; } } } else { containerManager.AddComponent(interfaceType, serviceType, name, scope); } } var moduleEles = root.Element("modules").Elements("module"); foreach (var ele in moduleEles) { var moduleType = Type.GetType(ele.Attribute("type").Value); IIocModule module = Activator.CreateInstance(moduleType) as IIocModule; containerManager.RegisterModule(module); } }
public static void RegisterModule(this IContainerManager containerManager, IIocModule module) { module.Load(containerManager); }
public static void RegisterModule(this IContainerManager containerManager, IIocModule module) { module.Load(containerManager); }
public static void AddModule(this IFunctionsHostBuilder builder, IIocModule module) { module.AddServices(builder); }