Is it possible to resolve a type from the container, change some properties on it, then use that instance when resolving other types that take the first type as a dependency, rather than returning a new instance?
From what Intellisense suggests, the extraData parameter on Locate() should be my friend, so here's the basics of a test that demonstrates what I want to achieve (I've attached a proof-of-concept):
var context = container.Locate<Context>();
context.Id = Guid.NewGuid();
var command = new TestCommand();
var handler = container.Locate<ICommandHandler<TestCommand>>(extraData: new { context });
handler.Handle(command);
Assert.AreEqual(context.Id, command.Result);
However, the test fails as the context I sent to Grace is not the same context that is injected into my handler (I've tried modifying the test to use Assert.Same on the two contexts, but it fails also).
So, is what I am trying to do possible, or am I just doing it wrong?
grace-injectable-values.zip
Is it possible to resolve a type from the container, change some properties on it, then use that instance when resolving other types that take the first type as a dependency, rather than returning a new instance?
From what Intellisense suggests, the
extraDataparameter onLocate()should be my friend, so here's the basics of a test that demonstrates what I want to achieve (I've attached a proof-of-concept):However, the test fails as the context I sent to Grace is not the same context that is injected into my handler (I've tried modifying the test to use Assert.Same on the two contexts, but it fails also).
So, is what I am trying to do possible, or am I just doing it wrong?
grace-injectable-values.zip