Skip to content
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

Add more methods for conditional registrations to the core library #4

Closed
dotnetjunkie opened this issue Apr 9, 2015 · 0 comments
Closed

Comments

@dotnetjunkie
Copy link
Collaborator

The core library currently contains methods for conditionally registering open generic types and decorators using RegisterOpenGeneric and RegisterDecorator. This feature should be extended to non-generic or closed-generic registrations as well.

The extension of this feature can partly replace RegisterWithContext method that is currently given as example in the documentation. Just like with is possible with the RegisterWithContext, the feature in the core library should allow the user to make a decision on its direct parent. Ideally this information should also be included for conditional open generic registrations and decorators.

In contrast with the RegisterWithContext extension method however, the built-in feature should not allow users to supply a factory delegate, but only allow supplying either an implementation type or a Registration instance. Allowing a user to supply a factory delegate would blind the diagnostic system and would make the registration transient and thereby force all parents up the chain to be transient as well (to prevent lifestyle mismatches / captive dependencies).

While RegisterWithContext allows the object graph to be built-up using runtime decisions, the new core feature should only allow to make decisions based on information known during the building of the object graph, just as is currently the case with both open generics and decorators. The predicate is called a finite number of times and the information burned in the compiled code that builds the object graph. This is important, because runtime information should never influence the structure of the object graph. The shape of the object graph should be fixed, and runtime information should instead be queried at runtime to change the application's call graph; not the object graph.

Although tempting, this new feature should not allow a registration to query information beyond its direct parent. Analyzing the parent's parent might seem useful, but will give incorrect results if direct parent is anything but transient (again causing the whole object graph to become transient).

While the RegisterWithContext only supports dependencies that are injected as constructor argument, the core feature should also support dependencies that are injected through property injection, since the core library supports property injection.

@dotnetjunkie dotnetjunkie added this to the Simple Injector v3.0 milestone May 6, 2015
@dotnetjunkie dotnetjunkie self-assigned this Jun 2, 2015
@dotnetjunkie dotnetjunkie changed the title Add RegisterWithContext method to the core library Add more methods for conditional registrations to the core library Jun 7, 2015
dotnetjunkie pushed a commit that referenced this issue Jun 10, 2015
Extra parameters added to IConstructorInjectionBehavior methods
BuildParameterExpression and Verify to make it possible to resolve
conditional registrations (related to #4)
dotnetjunkie pushed a commit that referenced this issue Jun 10, 2015
Removed the extra parameters from the
IConstructorInjectionBehavior.Verify method (related to #4). There
weren't needed.
dotnetjunkie pushed a commit that referenced this issue Jun 20, 2015
Test added that #4 has resolved this issue (fixes #8).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant