Skip to content

All Jobs instances are resolved from single service provider scope in asp.net core #16

Closed
wite27 opened this issue Jun 8, 2019 · 0 comments · Fixed by #19
Closed

All Jobs instances are resolved from single service provider scope in asp.net core #16

wite27 opened this issue Jun 8, 2019 · 0 comments · Fixed by #19
Labels
bug Something isn't working

Comments

@wite27
Copy link

wite27 commented Jun 8, 2019

According to https://github.com/TinkoffCreditSystems/Horarium/blob/master/src/Horarium.AspNetCore/JobFactory.cs#L16-L24 and https://github.com/TinkoffCreditSystems/Horarium/blob/master/src/Horarium/Handlers/ExecutorJob.cs#L52-L56 all jobs are resolved from captured IServiceProvider in JobsFactory constructor. This is because scope created at https://github.com/TinkoffCreditSystems/Horarium/blob/master/src/Horarium.AspNetCore/JobFactory.cs#L23 never used to resolve jobs, as its return type is IDisposable. Instead, jobs should be resolved from created scope like this:
_serviceProvider.CreateScope().ServiceProvider.GetService(type)
In particular, it affects using Horarium with EFCore, because DbContext should not to be used by multiple threads at one time.

@Bobreshovr Bobreshovr added the bug Something isn't working label Jun 8, 2019
Bobreshovr added a commit that referenced this issue Jun 13, 2019
#16: introduced IJobExecutionContext and IJobExecutionContextFactory
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants