Ejemplo n.º 1
0
 /// <summary>
 /// Override to add registrations to the container.
 /// </summary>
 /// <param name="builder">The builder through which components can be
 /// registered.</param>
 /// <remarks>
 /// Note that the ContainerBuilder parameter is unique to this module.
 /// </remarks>
 protected override void Load(Autofac.ContainerBuilder builder)
 {
     var assemblies = Assembly.GetExecutingAssembly();
     builder.RegisterAssemblyTypes(assemblies).As<IRunAfterEachRequest>().InstancePerRequest();
     builder.RegisterAssemblyTypes(assemblies).As<IRunAtStartup>();
     builder.RegisterAssemblyTypes(assemblies).As<IRunOnEachRequest>().InstancePerRequest();
     builder.RegisterAssemblyTypes(assemblies).As<IRunOnError>();
 }
Ejemplo n.º 2
0
        public void Register(Autofac.ContainerBuilder builder, ITypeFinder typeFinder)
        {
            builder.RegisterType<WorkflowEngine>().As<IWorkflowEngine>().InstancePerHttpRequest();
            builder.RegisterAssemblyTypes(typeFinder.GetAssemblies().ToArray())
               .AssignableTo<IAutoActivityHandler>()
               .AsImplementedInterfaces();

            Assembly[] assemblies = typeFinder.GetAssemblies().ToArray();
            builder.RegisterAssemblyTypes(assemblies)
               .AssignableTo<IAutoActivityHandler>()
               .AsImplementedInterfaces();

            //regisger  [UUID("ApplyQuota-2.0-Approve-ActivityExecutedEvent")]
            var handlers = typeFinder.FindClassesOfType(typeof(IAutoActivityHandler)).ToList();
            foreach (var handler in handlers)
            {
                object[] attrs = handler.GetCustomAttributes(typeof(UUIDAttribute), false);
                string uuid = string.Empty;
                if (attrs != null)
                {
                    foreach (UUIDAttribute attr in attrs)
                    {
                        uuid = attr.UUID;
                    }
                    builder.RegisterType(handler).As<IAutoActivityHandler>().Keyed<IAutoActivityHandler>(uuid)
                    .InstancePerHttpRequest();
                }
            }

            //regisger  [UUID("ApplyQuota-2.0-Approve-ActivityExecutedEvent")]
            var consumers = typeFinder.FindClassesOfType(typeof(IConsumer<>)).ToList();
            foreach (var consumer in consumers)
            {
                object[] attrs = consumer.GetCustomAttributes(typeof(UUIDAttribute), false);
                string uuid = string.Empty;
                if (attrs != null)
                {
                    foreach (UUIDAttribute attr in attrs)
                    {
                        uuid = attr.UUID;
                    }
                    var interfaceType = consumer.FindInterfaces((type, criteria) =>
                    {
                        var isMatch = type.IsGenericType && ((Type)criteria).IsAssignableFrom(type.GetGenericTypeDefinition());
                        return isMatch;
                    }, typeof(IConsumer<>))[0];
                    builder.RegisterType(consumer).As(interfaceType)
                    .Keyed(uuid, interfaceType)
                    .InstancePerHttpRequest();
                }
            }
        }
Ejemplo n.º 3
0
 protected override void Load(Autofac.ContainerBuilder builder)
 {
     builder.RegisterAssemblyTypes(Assembly.Load("EF-Learn.DAL"))
          .Where(t => t.Name.EndsWith("Dal"))
          .AsImplementedInterfaces()
         .InstancePerLifetimeScope();
     base.Load(builder);
 }