When using interfaces, where exactly should the hard implementation of each object be retrieved from. Is that done by creating a factory object for each type?
IRepository<User> userRepository = new UserRepository(connection); // Needs a dbconnection
userRepository.Create(user);
//Is this the best way?
IRepository<User> userRepository = RepositoryFactory.GetUserRepository(connection);
public static class RepositoryFactory
{
public static IRepository<User> GetUserRepository(DbConnection connection)
{
return new UserRepository(connection);
}
}
What is the best of most logical way to get a UserRepository object to work with? If I used a factory object for UserRepository, do I pass in the connection object or what is that process?
I’m sorry if I read your question incorrectly but you might want to take a look at
Inversion of Control and Dependency Injection and see how those would fit best for what you are trying to do.
IoC: http://visualstudiomagazine.com/articles/2010/08/01/inversion-of-control-patterns-for-the-microsoft-net-framework.aspx / http://joelabrahamsson.com/entry/inversion-of-control-introduction-with-examples-in-dotnet
Dependency Injection: http://www.blackwasp.co.uk/DependencyInjection.aspx