Search code examples
c#asp.net-web-apicastle-windsorautofac

Autofac register assembly types


In Castle, I used to do the following to register types from a different assembly:

Classes.FromAssemblyNamed("MyServer.DAL")
       .Where(type => type.Name.EndsWith("Repository"))
       .WithServiceAllInterfaces()
       .LifestylePerWebRequest(),

In Autofac, I change the above code to this:

builder.RegisterAssemblyTypes(AppDomain.CurrentDomain.GetAssemblies())
       .Where(t => t.Name.EndsWith("Repository"))
       .InstancePerRequest();

Is it correct?


Solution

  • This is the correct way:

    builder.RegisterAssemblyTypes(AppDomain.CurrentDomain.GetAssemblies())
           .Where(t => t.Name.EndsWith("Repository"))
           .AsImplementedInterfaces()
           .InstancePerRequest();