将 Castle Windsor 图书馆的 Classes.FromAssembly 迁移到 Autofac
Migrate Classes.FromAssembly of Castle Windsor Library To Autofac
我已经在温莎城堡注册了。 AutoFac 中的替代代码是什么?
//Transient
context.IocManager.IocContainer.Register(
Classes.FromAssembly(context.Assembly)
.IncludeNonPublicTypes()
.BasedOn<ITransientDependency>()
.WithService.Self()
.WithService.DefaultInterfaces()
.LifestyleTransient()
);
试试这个:
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))));
您不必使用 .InstancePerDependency()
方法来指定您的注册是暂时的,因为这是 Autofac
中的默认设置
我已经在温莎城堡注册了。 AutoFac 中的替代代码是什么?
//Transient
context.IocManager.IocContainer.Register(
Classes.FromAssembly(context.Assembly)
.IncludeNonPublicTypes()
.BasedOn<ITransientDependency>()
.WithService.Self()
.WithService.DefaultInterfaces()
.LifestyleTransient()
);
试试这个:
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))));
您不必使用 .InstancePerDependency()
方法来指定您的注册是暂时的,因为这是 Autofac