Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

ApplicationDbContext Scope

$
0
0

Hello everybody,

I am using ASP.NET Core 1.0 and I need to schedule tasks (Hangfire style). I am using FluentScheduler v5.1.3 with structuremap as a DI container.

The thing is, when I run jobs that use the EF Core, I get a context disposed exception.

I initliaze StructureMap simply populating it using an IServiceCollection (from asp.net core) where all services are registered as transient.

I start my job like this :

JobManager.AddJob(() => _sync.SyncFromDomain(vm.Domain), s => s.ToRunOnceIn(5).Seconds());

I don't initialize the job manager with a registry.

The job gets fired after 5 seconds but, as soon as I hit the repository code where the context is needed, this exception gets thrown :

Exception thrown: 'System.ObjectDisposedException' in Microsoft.EntityFrameworkCore.dll


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>