Ejemplo n.º 1
0
        public static T CreateInstance <T>(this RuleServiceProvider <T> ruleServiceProvider, string assemblyName)
        {
            if (ruleServiceProvider.ClassLoader == null)
            {
                ruleServiceProvider.ClassLoader = new ClassLoader <T>(assemblyName);
            }

            return(ruleServiceProvider.ClassLoader.Activate());
        }
        public virtual void RegisterRuleServiceProvider(string uri, string assemblyName)
        {
            try
            {
                if (this.RegistrationMap == null)
                {
                    RegistrationMap = new Dictionary <Uri, object>();
                }

                // TODO: Should we store the Type along with the created instance; say, in a Tuple?  This would be used for casting from object to the stored type in the dictionary value.
                var ruleServiceProvider =
                    new RuleServiceProvider <T> {
                    ClassLoader = new ClassLoader <T>(assemblyName)
                }.CreateInstance(
                    assemblyName);

                RegistrationMap.Add(new KeyValuePair <Uri, object>(new Uri(uri), ruleServiceProvider));
            }
            catch (Exception e)
            {
                throw new ConfigurationException($"Could not register driver: {assemblyName} against URI: {uri}", e);
            }
        }