unitycontainer/experimental

Allow passing MemberInfo to Injection Members to simplify selection

Opened this issue · 0 comments

ENikS commented

Description

Currently InjectionMethod only accepts "Name" of the method and tries to determine proper member based on parameters sent with the registration.

Problem

The selection process is rather involved operation and could add significant overhead to execution time.

Solution

In many cases performance could be improved if MethodInfo of the desired method is passed to the constructor. With that the developer would no longer be required to specify all parameters and only pass these that require specific resolution instructions.

For example, method InvokedMethod(string first, int second, int optional = 0) could be specified like this:

var info = typeof(xyz).GetMethod(nameof(xyz.InvokedMethod))
var invoke = new InjectionMethod(info, Inject.Parameter("first parameter"))
container.RegisterType(... invoke)

Impact

None.