The application I'm working on relies on Autofac as a DI container, and one of the reasons I decided to use it, among others, was the delegate function of the factory (see here )
This is great for all cases when I need to recreate the same elements several times, as is the case with some reports and related screens. Some reports (even the same type) are executed at the same time, but they only change according to their user parameters, so it makes sense (I think) to introduce factories to create instances, transfer free parameters and leave the rest of the application.
The problem is that each report is composed of a variable number of supporting reports (tasks), and each task implements the ITask interface. Each report can contain up to 50 different tasks, and each task encapsulates an exact business operation. One of the options that I have is to implement delegate factories and create them when necessary.
These tasks should be dynamically generated in factories and something like:
var myTaskA = _taskFactoryConcreteTaskA(); var myTaskB = _taskFactoryConcreteTaskB(); var myTaskC = _taskFactoryConcreteTaskC(); ... var myTaskZZ = = _taskFactoryConcreteTaskZZ();
it takes a lot of manual wiring (delegates, constructor, support fields, etc.), and something like
var myTaskA = _taskFactory.Create<ConcreteTaskA>(); var myTaskB = _taskFactory.Create<ConcreteTaskB>(); var myTaskC = _taskFactory.Create<ConcreteTaskC>(); ... var myTaskZZ = _taskFactory.Create<ConcreteTaskZZ>();
it would be incredibly less work, especially if _taskFactory wraps the container, as shown in this other post , but also basically means that I use the service locator to create my tasks.
What other options do I have that might be useful to you?
(NOTE: there is a good chance that I am completely unaware, and that I have to read a lot more about DI, in which case any input will be even more important)