Upgrade plugin from 3.30 to 3.40 - The operation cannot be completed because the DbContext has been disposed.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
9 Jahre weitere
Hi,
Can you copy-paste me the extension? I do not have method with 2 parameters.
J.
9 Jahre weitere
Hi,

By the way: for me this error occurs if I do call a method of my webservice more than once. I would like to call it multiple times during one connection.

J.
9 Jahre weitere
Hi,

I call method method from nope core.
This is in namespace Nop.Core.Infrastructure.DependencyManagement object ContainerManager


public T Resolve<T>(string key = "", ILifetimeScope scope = null) where T : class
        {
            if (scope == null)
            {
                //no scope specified
                scope = Scope();
            }
            if (string.IsNullOrEmpty(key))
            {
                return scope.Resolve<T>();
            }
            return scope.ResolveKeyed<T>(key);
        }


Best,
Rudolf
9 Jahre weitere
Hi,

Thank you. I used Resolve of:

EngineContext.Current.Resolve


I get next error in my (web)service constructor:

No scope with a Tag matching 'AutofacWebRequest' is visible from the scope in which the instance was requested. This generally indicates that a component registered as per-HTTP request is being requested by a SingleInstance() component (or a similar scenario.) Under the web integration always request dependencies from the DependencyResolver.Current or ILifetimeScopeProvider.RequestLifetime, never from the container itself.

9 Jahre weitere
Fixed next by reapplying InstancePerLifetimeScope()

I get however now the error: 'The operation cannot be completed because the DbContext has been disposed. ' for every request.

Quantis001 wrote:


No scope with a Tag matching 'AutofacWebRequest' is visible from the scope in which the instance was requested. This generally indicates that a component registered as per-HTTP request is being requested by a SingleInstance() component (or a similar scenario.) Under the web integration always request dependencies from the DependencyResolver.Current or ILifetimeScopeProvider.RequestLifetime, never from the container itself.

9 Jahre weitere
Hi,

Seems that if I remove the using in my webservice constructor makes it work. However, that might maybe lead to memory issues?

Where do you use this method with using? In the service constructor of your plugin?


//using (var scope = EngineContext.Current.ContainerManager.Container.BeginLifetimeScope())
            //{
            var scope = EngineContext.Current.ContainerManager.Container.BeginLifetimeScope();


I can across this: https://code.google.com/p/autofac/wiki/WcfIntegration

J.
6 Jahre weitere
marc wrote:
I am facing the same issue. I am also using filter provider and fetch the product using GetProductById() method. But it throws the same error DBContext has been disposed on GetById method. Here is my code:

The other posts in the thread show what you need:

You need to change your DependencyRegistrar.cs to have .InstancePerLifetimeScope()

and you'll need to remove the Constructors from the top of the class and add a manual entry to the _productService:

var _productService = EngineContext.Current.Resolve<IProductService>();


Thanks Marc, This is working for me :)
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.