This repository was archived by the owner on Mar 15, 2025. It is now read-only.
Conversation
Cycle detection now occurs when creating a child RequestInfo to ensure it is always checked when a child request is performed. Child requests are now created in providers instead: - Child requests should not be made in ServiceFactory. A ServiceFactory can be used to create another ServiceFactory (like FallibleServiceFactory), and the ServiceInfo used by the child RequestInfo will be wrong (it'll be for a Result<T, E> instead of a T even though FallibleServiceFactory makes the actual provided service a T) - Child requests should not be made in Services<S>. Providers can now be requested directly, which would bypass the entire Services<S> type. - Child requests cannot be made in Providers<S> because it only returns the providers. The RequestInfo is passed directly into the provider later, and Providers<S> has no control over that. - Providers know what type they're providing, so it makes sense to force them to add the type to the child request before invoking their inner service factory. Unfortunately, this means that users creating custom providers will have to remember to create the child requests themselves in their providers. There may be a way to force child requests to be created though using generics? Providers now take &self instead of &mut self. It greatly simplifies the logic for iterating over providers because the iterator no longer needs to take ownership of the provider to be able to use it. This means that SingletonProvider needs to have a lock in it, but this is still cheaper than requiring a lock on all providers. Due to the above changes, a large part of InjectorBuilder and Module needed to be rewritten. The above changes also opened up an opportunity to simplify how the builder types are implemented.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ServiceFactoryServiceconstraint to the provider implementationsAnyrather thanServiceServiceFactory::invokenow takes&self, meaning it doesn't need to be locked to be used in a thread-safe mannerFnrather thanFnMutnowFallibleServiceFactorynor theFn(previouslyFnMut) implementations need&mut self