Where to store objects like tie lines in an IoC template?

In my eternal quest to suck less, I am currently testing mvc Turbine for IoC dirty work.
I use the mvc Turbine nerd dinner example as a leadership, and everything looks pretty logical so far. Although I am referring to the turbine design here, I assume that the philosophy behind it is something common for the Safe to Read model and a rare podcast, I am new to the IoC concept, and I have a few questions.

So far, I have an IServiceRegistration entry for each IRepository that I want to register. For example:

public class UserRepositoryRegistration : IServiceRegistration
{
    public void Register(IServiceLocator locator)
    {
        locator.Register<IUserRepository, UserRepository>();
    }
}

The specific implementation of IUserRepository requires some configuration. Something like a connection string, or in this case, the path to the db4o file to use.

Where and to whom should I provide this information?

+5
source share
3 answers

Both Robert and Lucas hit the nail on the head with their answers. All the "extra things" for the account will live in the UserRepository class. This is currently a way to implement Turbine ND.

However, nothing prevents you from creating a new class called ConnectionStringProvider, which can then be "entered" into your UserRepository, which will provide a connection string (whether hard-coded or read from a configuration file.

The code may be as follows:

public class ConnectionStringProvider {
    public string ConnectionString {
        get{
             // your impl here
        }
    }
}

public class UserRepository {
   public UserRepository(ConnectionStringProvider provider){
        // set internal field here to use later
        // with db connection
   }
}

ConnectionStringProvider UserRepositoryRegistration, Turbine .

+3

, UserRepository, . , , .

, , . , IUserRepository , , - .

+2

, , , . , .

+1

All Articles