Exemplo n.º 1
0
        public void NewThreadScopedContext()
        {
            Container container;

            if (ContextExists())
            {
                throw new Exception($"Context already exists. Lifestyle = {_lifestyle}");
            }
            else
            {
                _lifestyle = "ThreadScoped";
                container  = new Container();
                container.Options.DefaultScopedLifestyle = new ThreadScopedLifestyle();
            }

            _context = new SimpleInjectorContainerContext(container);
        }
Exemplo n.º 2
0
        public void NewWebRequestContext()
        {
            Container container;

            if (ContextExists())
            {
                throw new Exception($"Container already exists. Lifestyle = {_lifestyle}");
            }
            else
            {
                _lifestyle = "WebRequest";
                container  = new Container();

                // Needed for SimpleInjector v5
                // See https://simpleinjector.readthedocs.io/en/latest/resolving-unregistered-concrete-types-Is-disallowed-by-default.html
                container.Options.ResolveUnregisteredConcreteTypes = true;

                container.Options.DefaultScopedLifestyle = new WebRequestLifestyle();
            }

            _context = new SimpleInjectorContainerContext(container);
        }