It's possible to register a class with a parameter expected to be passed from the point of creation?
I know it can be done something like this:
GlobalContainer.RegisterType<TUserProcessor>.Implements<IUserUpgrader>.
AsTransient.DelegateTo(
function: TUserProcessor
begin
Result := TUserProcessor.Create(GetCurrentUser);
end
);
But there the parameters are binded to the execution context where the container gets registered and not where the object get's intantiated.
Something like this it's possible for example?
GlobalContainer.Resolve<IMathService>([FCurrentUser]);
I know some peoble advocate to have very simple constructors, but there are times when a constructor parameter looks clearly the way to go:
The object constructed needs the object parameter to work, so the reference must be satisfied. The parameter also makes that constraint much more obvious looking at the class.
You can assign the reference in a method or property and raise and exception in every other method if you try to use the object without first making the assignment.. I don't like writing this type of code it's simply a waste of time, just use the constructor parameter and check there. Less code, the better IMO.
Also the object being passed it's local to the object that constructs the new object using the container (for example a Transaction object) and has some state (it's not a new object that I can get with the container).