-
-
Notifications
You must be signed in to change notification settings - Fork 142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature: Microsoft dependency injection implementation #370
feature: Microsoft dependency injection implementation #370
Conversation
You need to modify build.cake file. |
src/Splat.Microsoft.Extensions.DependencyInjection/SplatMicrosoftExtensions.cs
Outdated
Show resolved
Hide resolved
src/Splat.Microsoft.Extensions.DependencyInjection/MicrosoftDependencyResolver.cs
Outdated
Show resolved
Hide resolved
src/Splat.Microsoft.Extensions.DependencyInjection/MicrosoftDependencyResolver.cs
Outdated
Show resolved
Hide resolved
src/Splat.Microsoft.Extensions.DependencyInjection/MicrosoftDependencyResolver.cs
Outdated
Show resolved
Hide resolved
src/Splat.Microsoft.Extensions.DependencyInjection/MicrosoftDependencyResolver.cs
Outdated
Show resolved
Hide resolved
src/Splat.Microsoft.Extensions.DependencyInjection/MicrosoftDependencyResolver.cs
Outdated
Show resolved
Hide resolved
You'll probably have to implement something like a |
The contract functionality definitely has to remain as is, if a contract exists it's a different "context", this is mostly used by splat/rxui internal functionality. |
src/Splat.Microsoft.Extensions.DependencyInjection/SplatMicrosoftExtensions.cs
Outdated
Show resolved
Hide resolved
Alright I think that's all the stuff I can find. Rodney will likely do a sweep as well. Thanks @weitzhandler |
Thanks for your comments @glennawatson!
|
Essentially contracts give you independent registrations of the original one. so <A, contract null> is a different regristration pool to <A, contract "blah"> |
Contracts are commonly used by users in the scenario where they want to show different views based on contexts on the same view models. |
src/Splat.Microsoft.Extensions.DependencyInjection.Tests/DependencyResolverTests.cs
Outdated
Show resolved
Hide resolved
src/Splat.Microsoft.Extensions.DependencyInjection/MicrosoftDependencyResolver.cs
Outdated
Show resolved
Hide resolved
public struct ContractInjector<T>
{
public ConcurrentDictionary<string, T> TypeDictionary = new ConcurrentDictionary<string, T>();
}
public void Register<T>(Func<T> register, string contract)
{
if (string.IsNullOrWhitespace(contract))
container.Register<T>(register); // whatever the funciton name is in MSDI
else
container.Register<ContractInjector<T>>(register); // You'll likely have to get any existing ContractInjector's created and input it there against the string.
} Since this is mostly for RxUI benefit this is sufficient way to fix it. You can also add extension methods for the MS DI containers so that users can register on both. Solved. |
So no scopes at all? |
Don't think it helps no, it's a similar concept but not quite what we need. Unless you can see a way of achieving the same results with scopes. |
I'll ditch the scopes entirely, because it's wrong. Say we use it, if we have a contract and a type, it becomes a singleton under that contract, whilst when users register with splat they intend to register transients, right? Anyway, I'll finish it up a bit later. Thank you two for your comments and help! |
Yeah, a contract is independent of singleton/transient. |
Oh, didn't know that. Then I should change the
I did before commiting. |
It's failing on compile errors btw. |
Why doesn't |
Sorry about that. I'll make sure to perform this action on every commit. Apologies. |
…dded Splat DI tests
I think hasregistration was added later. Probably should have it. |
|
src/Splat.Microsoft.Extensions.DependencyInjection/MicrosoftDependencyResolver.cs
Outdated
Show resolved
Hide resolved
All the resources I found say inheritance of these classes can be a bit dangerous. They aren't really designed for it |
Currently it passes all included test cases and some more, but I think more testing can be added to the base |
src/Splat.Microsoft.Extensions.DependencyInjection/MicrosoftDependencyResolver.cs
Outdated
Show resolved
Hide resolved
@weitzhandler I think apart from that one last multithreading issue I think this is good to go and like you said further tests/monitoring. I know this has been a long process compared to some other PRs you done so thanks for your persistence. |
Thank YOU for your persistence, not only with this PR, but with the entire repo, and also for teaching me a lot of stuff, I'm so grateful! |
if list empty remove contract entirelysplat/src/Splat.Microsoft.Extensions.DependencyInjection/MicrosoftDependencyResolver.cs Lines 327 to 332 in 5c73294
This comment was generated by todo based on a
|
src/Splat.Microsoft.Extensions.DependencyInjection/MicrosoftDependencyResolver.cs
Show resolved
Hide resolved
Related: #378 |
What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
An implementation of
IDependencyResolver
forMicrosoft.Extensions.DependencyInjection
.Fixes #362.
Related to #233.
Please check if the PR fulfills these requirements