Scope was not available. Did you forget to call container.BeginScope()?

2k Views Asked by At

Hello I want to using castle windosr in .net core and I have get bellow error in .net core:

Scope was not available. Did you forget to call container.BeginScope()?

my code is :

         public IServiceProvider ConfigureServices(IServiceCollection services)
    {
        services.Configure<CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });
        services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
        var container = new WindsorContainer();
        //container.BeginScope();
        Bootstrapper.WireUp(container);
        FrameworkBootstrapper.WireUp(container);
        var configureServices = WindsorRegistrationHelper.CreateServiceProvider(container, services);
        return configureServices;
    }

I added the error image . full image for error

in your option if i add container.BeginScope(); after var container = new WindsorContainer(); Is it the right way? Is there any problem? WindsorRegistrationHelper is a package between .net core built in ioc and castle you can see on below link: https://github.com/volosoft/castle-windsor-ms-adapter

0

There are 0 best solutions below