SOF User
SOF User

Reputation: 7830

Migrate Classes.FromAssembly of Castle Windsor Library To Autofac

I have register this in castle windsor. what will be alternat code for this in AutoFac?

//Transient
        context.IocManager.IocContainer.Register(
            Classes.FromAssembly(context.Assembly)
                .IncludeNonPublicTypes()
                .BasedOn<ITransientDependency>()
                .WithService.Self()
                .WithService.DefaultInterfaces()
                .LifestyleTransient()
            );

Upvotes: 2

Views: 430

Answers (1)

Cyril Durand
Cyril Durand

Reputation: 16192

Try this :

builder.RegisterAssemblyTypes(context.Assembly)
       .Where(t => t.GetInterfaces().Any(i => i == typeof(ITransientDependency)))
       .AsSelf()
       .As(t => t.GetInterfaces().Where(i => t.Name.Contains(i.Name.Substring(1)))); 

You don't have to use the .InstancePerDependency() method to specify that you registration will be transient because this is the default in Autofac

Upvotes: 5

Related Questions