hmlongco / Resolver

Swift Ultralight Dependency Injection / Service Locator framework
MIT License
2.14k stars 187 forks source link

Resolver and Swift 5.5 structured concurrency compatibility #138

Closed DoubleREW closed 2 years ago

DoubleREW commented 2 years ago

First of all, thank you for your project, well-documented and easy to use.

I'm playing with the new Swift 5.5 structured concurrency, but I don't find how to register into a container a factory for a class marked with the attribute @MainActor. I've pushed a little sample project that explains the problem: https://github.com/DoubleREW/SampleWithActorsAndResolver

FirstViewModel is marked with attribute @MainActor and it's not registrable. SecondViewModel, instead, uses @MainActor attribute on properties and functions only, so doesn't prevent the build.

vykut commented 2 years ago

@hmlongco can you take a look at this? I'm running into the same issue when trying to inject classes annotated with global actors. Thanks!

yoller commented 2 years ago

If you register it on the main thread it works. I don't know if this could have some contraindications...