我正在使用 mvc.net 和 StructureMap 为我扫描和注册所有存储库和服务。现在我想通过 Singleton 注册和缓存。我能怎么做?
IContainer container = new Container(x => {
// Register Repositories and Services
x.Scan(y => {
y.AssemblyContainingType<SomeRepository>();
y.AssemblyContainingType<SomeService>();
y.IncludeNamespaceContainingType<SomeRepository>();
y.IncludeNamespaceContainingType<SomeService>();
});
// Register Controllers
x.Scan(y => {
y.TheCallingAssembly();
y.AddAllTypesOf<IController>().NameBy(type => type.Name.Replace("Controller", ""));
});
});