From the code perspective you should just disable "new" constraint on factory interface:
public interface IDataRepositoryFactory
{
T GetDataRepository<T>() where T : IDataRepository; //, new();
}
public class DataRepositoryFactory : IDataRepositoryFactory
{
public T GetDataRepository<T>() where T : IDataRepository//, new()
{
return ObjectBase.Container.GetExportedValue<T>();
}
}
From the design point of view repositories look a bit complicated:
For me IDataRepository (non-generic) and RepositoryBase seem redundant, but that depends of the exact case (probably you didn't provide enough details). I'd use IDataRepository<T> -> IUserRepository:IDataRepository<User> -> UserRepository
inheritance chain.
Also it's not clear what types belong to BLL.
For example, this breakdown looks all right to me:
- BLL:
User
IUserRepository:IDataRepository<User>
- DAL/Infrastructure:
IDataRepositoryFactory
IDataRepositoryFactory:IDataRepositoryFactory
IDataRepository<T>
UserRepository
In general I'd suggest to simplify code structure and start with the simplest possible way, then adding new interfaces/classes when you really need them.