1

I have a set of services that are used to read/write to the database. These get injected into my controllers:

ISystemSettingService _systemSettingService = null;
IStatusTypeService _statusTypeservice = null;

public MyController(
    ISystemSettingService systemSettingService,
    IStatusTypeService statusTypeservice)
{
    _systemSettingService = systemSettingService;
    _statusTypeservice = statusTypeservice;
}

So when I need something from _systemSettingService I can easily get it. Now I also have some static helper classes/functions which I call from MyController. In these functions I often need access to the services so I can access the DB. e.g. I have a Validate(string userData, ISystemSettingService systemSettingService) function that accepts some data passed in from the user.

So far, into the Validate function I have been passing in the _systemSettingService so I can use it. I'm not sure this is correct.

My question - is my approach correct or, in the Validate function should I be creating a unity container to Resolve an instance of my ISystemSettingService or, as I have been reading about, should my helper class NOT be static, and I should inject ISystemSettingService into the constructor which will apparently make unit testing easier.

I'm a bit confused! Thanks.

Percy
  • 2,855
  • 2
  • 33
  • 56

0 Answers0