Simple, clean dependency injection with Autofac

Autofac is a Dependency injection or inversion of control mechanism with a very low learning curve. Just add code to the global asax, register your types and your ready:

public void OnApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
            IocConfig.RegisterDependencies();
        }

Registering types:

public static void RegisterDependencies()
        {
            var builder = new ContainerBuilder();
            builder.RegisterControllers(typeof(MvcApplication).Assembly);
            builder.RegisterModelBinders(typeof(MvcApplication).Assembly);

            // register the models and repository's in the business layer
            builder.RegisterAssemblyTypes(Assembly.Load("Business")).Where(t => t.Name.EndsWith("Repository")).AsImplementedInterfaces();
// classes with autowiring properties builder.RegisterType().PropertiesAutowired(); builder.RegisterType().PropertiesAutowired(); builder.RegisterType().PropertiesAutowired();

 

{{opmerking.Naam}}:

{{opmerking.OpmerkingText}}

            

Saving your comment....

Naam is verplicht!
Email is verplicht!
Opmerking is verplicht!