I have DataProvider class (DAL) that requires "year" as parameter. It used like this:
using (var provider = new DataProvider(year))
{
provider.SomeRepostitory.DoSomethingUsefull();
}
DataProvider constructor code deals with configuration - so it can throw exceptions. And exception throwable constructors are not recommended. So I added Init method and put all throwable code there:
var provider = new DataProvider();
provider.Init(year);
But now there are two lines of code instead of one and as provider created many times across the code, i put these two lines into fabric static method:
using (var provider = DataProvider.Create(year))
{
...
}
Is it ok or is there a better solution?
Thank you in advance!