Skip to content
This repository was archived by the owner on Mar 15, 2025. It is now read-only.

Improve ergonomics#35

Draft
TehPers wants to merge 26 commits intomainfrom
usability
Draft

Improve ergonomics#35
TehPers wants to merge 26 commits intomainfrom
usability

Conversation

@TehPers
Copy link
Copy Markdown
Owner

@TehPers TehPers commented May 27, 2021

  • Relaxed constraints for ServiceFactory
    • Moved Service constraint to the provider implementations
    • Result only constrained by Any rather than Service
  • ServiceFactory::invoke now takes &self, meaning it doesn't need to be locked to be used in a thread-safe manner
    • Implemented on Fn rather than FnMut now
    • Neither FallibleServiceFactory nor the Fn (previously FnMut) implementations need &mut self

@TehPers TehPers changed the title Improve usability Improve usability of service factories May 27, 2021
TehPers added 12 commits April 7, 2022 12:16
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.
@TehPers TehPers changed the title Improve usability of service factories Improve usability Apr 17, 2022
@TehPers TehPers changed the title Improve usability Improve ergonomics Apr 17, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant