public IComponentInfo CreateInfo(XAccessor x) { string id = x.GetStringValue(ID_ATTR); bool? lcManage = x.GetValue<bool>(LIFECYCLE_MANAGEMENT_ATTR); Type serviceType = null; string xServiceType = x.GetStringValue(SERVICE_TYPE); if (!string.IsNullOrEmpty(xServiceType)) { serviceType = Reflector.LoadType(xServiceType); } Type componentType = null; string xComponentType = x.GetStringValue(COMPONENT_TYPE); if (!string.IsNullOrEmpty(xComponentType)) { componentType = Reflector.LoadType(xComponentType); } List<IPolicy> policies = new List<IPolicy>(); XAccessor xPolicies = x.NavigateToSingleOrNull(POLICY); if (xPolicies != null) { foreach (var xPolicy in xPolicies.Children) { if (xPolicy.IsComment) continue; IPolicy policy = CreatePolicy(xPolicy); policies.Add(policy); } } IComponentInfo info = new ComponentInfo(id, serviceType, componentType, policies, lcManage ?? false); return info; }
private IPolicy CreatePolicy(XAccessor xPolicy) { IReadOnlyDictionary<string, Type> dict = _cfg.LoadCustomizedPolicies(); IPolicy policy = null; //Note:check build-in first switch (xPolicy.LocalName) { case "singleton": policy = new SingletonPolicy(); policy.Initialize(xPolicy); break; case "factory": policy = new FactoryPolicy(); policy.Initialize(xPolicy); break; case "instance": policy = new InstancePolicy(); policy.Initialize(xPolicy); break; case "stateless": policy = new StatelessPolicy(); policy.Initialize(xPolicy); break; case "activator": policy = new ActivatorPolicy(); policy.Initialize(xPolicy); break; case "setter": policy = new SetterPolicy(); policy.Initialize(xPolicy); break; default: if (dict.ContainsKey(xPolicy.LocalName)) { policy = Activator.CreateInstance(dict[xPolicy.LocalName]) as IPolicy; policy.Initialize(xPolicy); } break; } if (policy == null) throw new UnknownPolicyException(string.Format("Unknown policy:[{0}].", xPolicy.LocalName)); return policy; }
public XAccessor NavigateToSingle(string xpath) { XAccessor x = NavigateToSingleOrNull(xpath); if (x != null) { return(x); } else { ExceptionHelper.ThrowNodeNotFoundException(xpath); } return(null); }
public override void Initialize(XAccessor x) { _teardown = x.GetValue<bool>(TEARDOWN_ATTR) ?? false; var xParams = x.NavigateToList(PARAM); foreach (var xParam in xParams) { string name = xParam.GetStringValue(NAME_ATTR); string val = xParam.GetStringValue(VALUE_ATTR); if (string.IsNullOrEmpty(name)) ExceptionHelper.ThrowPolicyInitNullError(this.GetType(), NAME_ATTR); _injectionHints.Add(name, val); } }
public string GetStringValue(string xpath = null) { if (string.IsNullOrEmpty(xpath)) { return(_node.InnerText); } else { XAccessor x = NavigateToSingleOrNull(xpath); if (x != null) { return(x._node.InnerText); } else { return(null); } } }
public void Initialize(XAccessor x) { }
public abstract void Initialize(XAccessor x);
public void Initialize(XAccessor x) { //Note:No additional settings. }