0

having a fresh setup of asp.net core 5 app gives me the problem of not beeing able to set a per web request scope as SimpleInjector tells me to setup a scoped default lifestyle which is in an old package. This article from simpleinjector help says there is a integration package but cannot find any way to setup correctly without getting the excpetion when using the request lifetime scope, see code below.

public static class ContainerManager
{
    private static readonly Lazy<Container> _container = new Lazy<Container>(ConfigureServices);

    private static Container ConfigureServices()
    {
        var assemblies = AppDomain.CurrentDomain.GetAssemblies().Where(a => a.GetName().Name.StartsWith("Nordmann.Timetables")).ToList();
        var container = new Container();
        
        //General
        var lifeStyle = Lifestyle.CreateHybrid(Lifestyle.Scoped, Lifestyle.Transient);
        DomainConfig.Register(new DomainEventStoreProvider(container));
        container.Register<IDomainEventStore, InMemoryDomainEventStore>();
        container.Register<IEventDispatcher, Dispatcher>(Lifestyle.Scoped);
        
        container.Collection.Register(typeof(IEventHandler<>), assemblies);
        container.Register(typeof(IQueryHandler<,>), assemblies);
        //CM
        container.Register<INordmannUnitOfWork, NordmannUnitOfWork>(Lifestyle.Scoped); //WebRequest
        container.Register<UserApplicationService>(Lifestyle.Transient);
        container.Verify();
        return container;
    }
    public static Container Instance { get => _container.Value; }
}
2
  • Your question unfortunately contains too little details. Please: 1. Show a Minimal, Reproducible Example. Using the given code sample I'm unable to reproduce the issue, and 2. Post the complete error information in text format (i.e. exception type, message, and stack trace of the exception and all inner exceptions).
    – Steven
    Sep 5, 2022 at 15:57
  • 3. Explain why you are overriding the default ServiceScope Reuse Behavior. What are you trying to achieve?
    – Steven
    Sep 5, 2022 at 15:58

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.