-
Notifications
You must be signed in to change notification settings - Fork 29
-
I'm looking at this example.
As far as I understand this is the way of binding a factory, so that all dependencies of the returned instance get resolved automatically, except for the func arguments, which are being "overridden".
Is this correct, is this line:
ctx.Inject<Dependency>(out var dependency);
the equivalent of writing this using Unity:
container.Resolve<IDependency>(new ParameterOverride("dependencyId", dependencyId));
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 1 comment
-
@Nevca I'm not sure if this is the same. In example, the Bind<int>().To<int>("dependencyId") call specifies to use this code as it is: dependencyId when resolving a dependency of type int.
In the example, near the end, there is also code that will be generated:
public IService Root { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { Func<int, int, IDependency> transientFunc1 = [MethodImpl(MethodImplOptions.AggressiveInlining)] (dependencyId, subId) => { int transientInt324 = subId; int transientInt323 = dependencyId; if (_root._singletonClock43 is null) { using (_lock.EnterScope()) { if (_root._singletonClock43 is null) { _root._singletonClock43 = new Clock(); } } } Dependency localDependency65 = new Dependency(_root._singletonClock43, transientInt323, transientInt324); return localDependency65; }; return new Service(transientFunc1); } }
Pay attention to: int transientInt323 = dependencyId;.
And if the binding is changed to Bind<int>().To<int>("999"), the generated code will change to: int transientInt323 = 999;
Beta Was this translation helpful? Give feedback.