canton7 / Stylet

A very lightweight but powerful ViewModel-First MVVM framework for WPF for .NET Framework and .NET Core, inspired by Caliburn.Micro.
MIT License
995 stars 144 forks source link

Scoped dependency resolving #82

Closed Bert-Proesmans closed 5 years ago

Bert-Proesmans commented 5 years ago

Hi!

I have integrated StyletIoC into my libs and am currently working on a project that involves Hangfire. To consolidate all foundational libraries accross my application i'd like to use Stylet's IoC container as JobActivator for Hangfire. An sich this easy.

There are types like PerformContext and CancellationToken provided by Hangfire and also injected by Hangfire on method call. These types can be used to do meta-things with the running task. I'd have to put these types into the interface method prototypes, and by doing so introducing unnecessary dependencies. Note that the job interface needs to be shared by caller and callee (implementing class assembly).

These types can also be injected through the use of a custom JobActivator, which has access to the scope information provided by Hangfire. The scope, and its data, is limited to the job invocation. The idea is to build an extension that provides some kind of scope awareness or temporary type-to-instance binding to the IoC container. Do you have any suggestions to keep this simple and lightweight? I'm not sure if you've used Hangfire before, maybe i could approach it differently?

Bert

canton7 commented 5 years ago

I'm afraid I haven't used hangfire, so most of your question doesn't make sense to me.

If you need more granular scoping, I'm afraid StyletIoC isn't for you. I did add per-request scoping to it once upon at time, when I used it in a web application, but it added quite a bit of (relative) complexity and cost which simply weren't needed for WPF, so I ripped that back out.

I'd recommend using a more featureful container (e.g. Autofac), as your container, and configuring Stylet to use it also.

Bert-Proesmans commented 5 years ago

Ok, thanks for the advice!