如何在扫描程序集时添加一些范围? Google 似乎对“structuremap scan cacheby”不太满意:/
ObjectFactory.Configure(registry =>
{
registry.Scan(x =>
{
x.AssemblyContainingType(typeof(IRepository<>));
x.With<DefaultConventionScanner>();
});
}
最佳答案
这里有一种方法可以让它与更新的 IRegistrationConvention API 一起工作:
public class SingletonConvention : IRegistrationConvention
{
#region IRegistrationConvention Members
public void Process(Type type, Registry registry)
{
registry.For(type).Singleton();
}
#endregion
}
可以这样使用:
container.Configure(registry =>
{
registry.Scan(x =>
{
x.AssemblyContainingType<Foo>();
x.AddAllTypesOf<IFoo>();
x.Convention<SingletonConvention>();
});
});
关于c# - StructureMap、扫描程序集和范围界定,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/566815/