Monday 15 September 2014

c# - Where to keep things like connectionstrings in an IoC pattern? -


In my eternal search for at least sucking, I am currently investigating the MVC turbine for doing IoC dirty work .
I am using the example of mvc turbine stupid food as a lead and thus look at things logically so far. Although I am pointing towards the turbine project, I am guessing the philosophy behind it, something to read and the pattern for rare podcast is normal, I am new to the IOC concept and I have some questions.

So far, I have an Iisisregistration entry for each IRPorporation which I want to register
For example:

  public class UserRepositoryRegistration: IServiceRegistration {public zero Register (IServiceLocator locator) {locator. Registrar & lt; IUserRepository, UserRepository & gt; (); }}  

Solid implementation of IUserRepository however requires some configuration. The path of the db4o file to use some connection string or in this case.

Where and how should I give this information?

Both Robert and Lucas hit the nail on their head with their answers. All "additional goods" for the account will remain within the User Repository Class, in this way the Turbine ND has been implemented in the present.

However, there is nothing that prevents you from creating a new class called Connection String Providers that can be injected into your user repository that will provide the connection string (whether it is hard-coded Or read from a config file.

The code can be as follows:

  public class ConnectionStringProvider {public string ConnectionString {get {// around yourself}}} public Category UserRepository {Public UserReposit Ory (ConnectionStringProvider Provider) {// // Set the internal area here to use // later with db connection}}  

From here, you can use ConnectionStringProvider for UserRepositoryRegistration Adding a registration category and turbines will handle the rest for you.


No comments:

Post a Comment