I have the following code:
public AccountService(ModelStateDictionary modelStateDictionary, string dataSourceID)
{
this._modelState = modelStateDictionary;
this._accountRepository = StorageHelper.GetTable<Account>(dataSourceID);
this._productRepository = StorageHelper.GetTable<Product>(dataSourceID);
}
public AccountService(string dataSourceID)
{
this._accountRepository = StorageHelper.GetTable<Account>(dataSourceID);
this._productRepository = StorageHelper.GetTable<Product>(dataSourceID);
}
Is there some way that I can simplify the constructors so each doesn't have to do the StorageHelper calls?
Also do I need to specify this. ?
public AccountService(ModelStateDictionary modelStateDictionary, string dataSourceID)
: this(dataSourceID)
{
this._modelState = modelStateDictionary;
}
This will first call your other constructor. You can also use base(...
to call a base constructor.
this
in this case is implied.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With