First some background,
I am currently working on a relatively large Asp.Net MVC application that I have tried, as much as possible, to design around a domain driven model, using good design principles. We are required to do all database access via stored procedures (Oracle). In this application, I have a variety of controllers that use service objects to do business logic and in turn call on repository objects to accomplish access.
I have just been informed that the dba requires several common parameters to be passed to every stored procedure in addition to the parameters required to fetch/update/insert the data. These parameters include the username, ip address and domain of the user making the original web request. This data is then used in by each stored procedure to call functions that log access and check that the user has permissions to execute that particular stored procedure.
I have tried to gently explain that I feel this is poor design and that the .Net application could simply call stored procedures dedicated to logging and checking permissions whenever necessary. Unfortunately, this methodology is well established in the environment and the dba is unwilling to change it.
So now to my question,
Does anyone have any good ideas on how I can accomplish retrieving these extra parameters and deliver them to the repository objects without making a huge mess? From what I can tell this data is only available from the web context when in the controller layer. This means passing the extra data to class in the service layer and then on to each repository class. I’d like to minimize the pain here as much as possible.
If you are using dependency injection (you are aren’t you – it is a larger project)
you can simply inject the service into the controller. The repository then is injected into the service. The repository’s construction would take IUserSettings (or whatever its called) which is a concrete implementation of the details you require. Its then available to every repository.
public YourRepositoryClass(IUserSettings userSettings) { _userSettings = userSettings; }and voila – its available.