public static void RegisterRules(this Container container, Action <IRuleTypeScanner> scanAction)
        {
            var scanner = new RuleTypeScanner();

            scanAction(scanner);
            var ruleTypes = scanner.GetRuleTypes();

            container.Collection.Register(typeof(Rule), ruleTypes);
        }
 /// <summary>
 /// Registers fluent rule classes with the container.
 /// </summary>
 /// <param name="builder">Container builder.</param>
 /// <param name="scanAction">Configuration action on the rule type scanner.</param>
 /// <returns>Rule types registered with the container.</returns>
 public static Type[] RegisterRules(this ContainerBuilder builder, Action<IRuleTypeScanner> scanAction)
 {
     var scanner = new RuleTypeScanner();
     scanAction(scanner);
     var ruleTypes = scanner.GetRuleTypes();
     builder.RegisterTypes(ruleTypes)
         .AsSelf()
         .InstancePerDependency();
     return ruleTypes;
 }
Beispiel #3
0
        private static Type[] AddRules(this IServiceCollection services, Assembly[] assemblies)
        {
            var scanner = new RuleTypeScanner();

            scanner.Assembly(assemblies);
            var ruleTypes = scanner.GetRuleTypes();

            services.AddManyScoped(ruleTypes);

            return(ruleTypes);
        }
Beispiel #4
0
        /// <summary>
        /// Registers fluent rule classes with the container.
        /// </summary>
        /// <param name="builder">Container builder.</param>
        /// <param name="scanAction">Configuration action on the rule type scanner.</param>
        /// <returns>Rule types registered with the container.</returns>
        public static Type[] RegisterRules(this ContainerBuilder builder, Action <IRuleTypeScanner> scanAction)
        {
            var scanner = new RuleTypeScanner();

            scanAction(scanner);
            var ruleTypes = scanner.GetRuleTypes();

            builder.RegisterTypes(ruleTypes)
            .AsSelf()
            .InstancePerDependency();
            return(ruleTypes);
        }
Beispiel #5
0
        RegisterRuleRepository(this ContainerBuilder builder, Action <IRuleTypeScanner> scanAction)
        {
            var scanner = new RuleTypeScanner();

            scanAction(scanner);
            var ruleTypes = scanner.GetRuleTypes();

            builder.RegisterTypes(ruleTypes)
            .AsSelf()
            .InstancePerDependency();

            builder.RegisterType <AutofacRuleActivator>()
            .As <IRuleActivator>();

            return(builder.RegisterType <RuleRepository>()
                   .As <IRuleRepository>()
                   .SingleInstance()
                   .OnActivating(e =>
            {
                e.Instance.Activator = e.Context.Resolve <IRuleActivator>();
                e.Instance.Load(s => s.From(scanAction));
            }));
        }