예제 #1
0
        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);
        }
예제 #2
0
        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;
        }