VContainer
VContainer copied to clipboard
Implementing command pattern with Vcontainer
The way i see it right now there are two possible ways to do this, in both way there would be a factory that would create the commands the difference is how we inject dependencies to the actual command:
-
Registering the factory itself then in whatever class we will use to create a new command we will inject the dependencies of the command to that class and pass it to the command.
-
Registering a callback that would create the command and use IObjectResolver to resolve and forward whatever dependencies the command would need.
However if we take approach 1 I fear it could lead to big loading times of the scope, while using approach 2 would result in longer runtime when creating a command since we need to directly resolve it.
How do you suggest to implement this?
You can try this: https://github.com/Bezarius/UMediator
The performance of both forms is probably not much different. In general, the bounds are more correct if you rely only on the Factory rather than directly on the IObjectResolver. So we should consider 1 first. But it might depend on implementation details.