我想在 web 表单中使用 DryIoc 容器, 我使用示例代码:https://github.com/dadhi/DryIoc/blob/master/docs/DryIoc.Docs/ReuseAndScopes.md#reuse-and-scopes 但是每次我问,我都会从容器中得到一个新实例:
var container = new Container(rules => rules.WithDefaultReuse(Reuse.Scoped));
container.Register<ScopeService>();
_serviceContainer = container;
using (var scope = container.OpenScope())
{
var oSingleton = scope.Resolve<ScopeService>();
Debug.WriteLine($"APPLICION SINGLETON : {oSingleton.ID}");
var oSingleton2 = scope.Resolve<ScopeService>();
Debug.WriteLine($"APPLICION SINGLETON2 : {oSingleton2.ID}");
}
我在单例重用中描述了我的服务,但是我从容器中得到了一个新实例