Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • tommy 3 posts 73 karma points
    Dec 01, 2017 @ 07:19
    tommy
    0

    Autofac + Umbraco 7. Auto-register all assemblies dangerous?

    Is it dangerous or will it cause any strange and obscure bugs if I use Autofac's assembly scanning to automatically register everything (e.g. controllers, interfaces, etc.). The code is below:

    public class DependencyInjectionConfig : IApplicationEventHandler {
    public void OnApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext) { var builder = new ContainerBuilder(); var plugins = new List

        // Scan and auto-register EVERYTHING with an interface. This picks up MVC controllers in plugins too!
        builder.RegisterAssemblyTypes(assemblies)
            .Where(t => !t.GetCustomAttributes<ExcludeAutoRegistrationAttribute>().Any())
            .AsImplementedInterfaces()
            .AsSelf();
    
        var container = builder.Build();
        var resolver = new AutofacWebApiDependencyResolver(container);
    
        GlobalConfiguration.Configuration.DependencyResolver = resolver;
        DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
    
    }
    
    
    public void OnApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
    {
    }
    
    
    public void OnApplicationInitialized(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
    {
    }
    

    }

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies