Inject new paramertes in class used all over the project
I am working on a legacy project with dotnet Core. I have a class lets say:
public OrderModel(int userAccountId, Company company) : base(userAccountId)
{
Company = company;
}
Unfortunately, the class is being initiated all over the project and no injected, like the following about a million times:
var orderModel = new OrderModel(userAccount.Id, company)
Now i want to inject more parameters to the OrderModel class, but that will need to update all the new OrderModel initiations in all the solution, I tried to create a factory class and inject the new parameters there like this:
public class OrderModelFactory
{
private readonly IConfiguration _configuration;
public OrderModelFactory(IConfiguration configuration, IAmsPortal amsPortal, IOptions<AmsPortalOptions> amsOptions)
{
_configuration = configuration;
}
public OrderModel Create(int userAccountId, Company company, OrderInvoiceTransactions orderInvoiceTransactions,
IMapper mapper = null, IInsuranceService insuranceService = null,
IAhoyTransactionsService ahoyTransactionsService = null)
{
return new OrderModel(
userAccountId,
company,
_configuration, // newly Injected
);
}
}
but this also will lead to update all the initiations in the solution,
Any Ideas what is the fastest way to solve this taking in consideration that I dont have time to refactor the whole project now?