Web 形式使用 DryIOC 有困难

问题描述 投票:0回答:0

我想在 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}");
            }

我在单例重用中描述了我的服务,但是我从容器中得到了一个新实例

webforms inversion-of-control dryioc
© www.soinside.com 2019 - 2024. All rights reserved.