-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
Summary
Implement factory and delegate injection mechanisms in AttributedDI to allow resolving factories/delegates for services (e.g. Func<T> and custom delegate types).
Motivation
- Improve flexibility when constructing services that require runtime parameters.
- Avoid boilerplate factory types in user code while keeping DI-friendly patterns.
- Provide a clear, documented approach that works well with the library's AOP-style registration.
Proposed APIs / Examples
-
Direct Func resolution
- Allow consumers to request
Func<IMyService>which returns a newIMyServiceinstance when invoked.
- Allow consumers to request
-
Delegate generation
- Support generating delegates that map to service constructors, e.g.:
public delegate IMyService Create(string param, int val); // Container resolves Create -> delegate that constructs/resolves IMyService using provided args
- Support generating delegates that map to service constructors, e.g.:
Considerations / Constraints
- Func approach may require generating resolver code per service or inspecting constructors to decide generation; avoid forcing attributes on services if possible.
- Delegate generation must be compatible with common mocking/proxy frameworks (Moq, Castle) to avoid false anti-patterns; determine what limitations exist with dynamic proxying of delegate-returning registrations.
- Decide lifecycle semantics (transient vs scoped/singleton) for factories and produced instances and document them.
Acceptance Criteria
- Support resolving
Func<T>from the container. - Support resolving custom delegates that accept parameters and return service instances.
- Document limitations and compatibility notes with Moq / Castle Proxy and typical testing frameworks.
- Add clear usage examples in README or docs.
- Add tests that verify delegate resolution works and respects service lifetimes.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels