public void Configuration(IActivatingEnvironment environment, IServiceContainer container)
        {
            // We have to register the services at the application configuration stage.
            // Since there are some IoC implementations cannot register types after resolve instances.
            var types = new List <Type>();

            foreach (var assembly in environment.GetAssemblies())
            {
                if (!assembly.IsDynamic)
                {
                    IEnumerable <Type> assemblyTypes;
                    try
                    {
                        assemblyTypes = assembly.GetTypes();
                    }
                    catch (ReflectionTypeLoadException ex)
                    {
                        assemblyTypes = ex.Types.TakeWhile(type => type != null);
                    }
                    types.AddRange(assemblyTypes);
                }
            }
            ConfigureServices(container, types.ToArray());
            ConfigureClients(container, types.ToArray());
        }
Exemplo n.º 2
0
 /// <summary>
 /// Specify Unity as the service container to be used by the application.
 /// </summary>
 /// <param name="hostingEnvironment">An instance of <see cref="IActivatingEnvironment"/>.</param>
 /// <returns>The <see cref="IActivatingEnvironment"/>.</returns>
 public static IActivatingEnvironment UseUnity(this IActivatingEnvironment hostingEnvironment)
 {
     if (hostingEnvironment == null)
     {
         throw new ArgumentNullException(nameof(hostingEnvironment));
     }
     ServiceContainer.SetProvider(() => new UnityServiceContainer());
     return(hostingEnvironment);
 }
 public void Configuration(IActivatingEnvironment environment, IServiceContainer container)
 {
     // We have to register the controllers at the application configuration stage.
     // Since there are some IoC implementations cannot register types after resolve instances.
     foreach (var assembly in environment.GetAssemblies())
     {
         if (!assembly.IsDynamic)
         {
             container.RegisterMvcControllers(assembly);
         }
     }
 }
Exemplo n.º 4
0
        public void Configuration(IActivatingEnvironment environment, IServiceContainer container, IServiceCollection services)
        {
            // We have to register the controllers at the application configuration stage.
            // Since there are some IoC implementations cannot register types after resolve instances.
            foreach (var assembly in environment.GetAssemblies())
            {
                if (!assembly.IsDynamic)
                {
                    container.RegisterMvcControllers(assembly);
                }
            }
            services.Insert(0, ServiceDescriptor.Transient <IStartupFilter, ServiceBridgeStartupFilter>());
            var httpContextAccessor = new HttpContextAccessor();

            services.AddSingleton <IHttpContextAccessor>(httpContextAccessor);
            services.Replace(ServiceDescriptor.Singleton <IControllerActivator, ServiceBasedControllerActivator>());
            container.RegisterInstance <IHttpContextAccessor>(httpContextAccessor);
        }
Exemplo n.º 5
0
 public Startup(IActivatingEnvironment environment)
 {
     environment.UseAutofac();
 }
Exemplo n.º 6
0
 public Activator(IActivatingEnvironment environment)
 {
     environment.UseAutofac();
 }
Exemplo n.º 7
0
 public ServiceBridgeActivator(IActivatingEnvironment environment)
 {
     environment.Use(ServiceContainer.Current);
 }