I’m not sure the TPL surfaces enough for this to be viable, and as such, feel free to just point out alternative patterns that work instead. 🙂
I’m trying to figure out if I can use Ninject for ctor-injected dependencies that should ideally be scoped to a particular root/parent Task instance.
It’s somewhat similar to asp.net request scope, but in this scenario, it’s a console app that’s creating N different Tasks that will run in parallel. I’m wondering if there’s an ability to get Ninject to do the runtime dependency injection based on each of those root Task instances such that the object graph created as part of each task shares the same instances of a given interface, but the different tasks all have separate instances.
Thanks!
[EDIT] continuing to search, it looks like the InNamedScope might be the right answer based on the description of “define that objects are the scope for their dependencies”
If I understand your question correctly,
InNamedScopeis a good choice. The other alternative isInCallScope. This blog post has a good discussion of the differences:Here, the
SheetDataRepositoryuses theExcelSheetthat’s in scope. The article explains in greater detail.