Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
2 different base classes or 1 class or something else?
Message
 
 
À
16/01/2015 11:29:41
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01613723
Message ID:
01613743
Vues:
34
>>Hi everybody,
>>
>>We have the following base repository class
>>
>>
>>namespace SysManager.Repository
>>{
>>    public abstract class RepositoryBase<T> : IRepository<T> where T : class
>>    {
>>        protected readonly ISiriusSqlContext _siriusContext;
>>
>>        protected readonly IDbSet<T> _dbSet;
>>        private readonly IExceptionParser _exceptionParser;
>>
>>        public RepositoryBase(ISiriusSqlContext context)
>>        {
>>            _siriusContext = context;
>>            _dbSet = _siriusContext.Set<T>();
>>            _exceptionParser = new ExceptionParser();
>>            
>>        }
>>    etc.
>>
>>
>>Now, I want to be able to optionally enhance it, e.g. I want to be able to pass an extra class but only in some cases, e.g. something like
>>
>>
>>    public abstract class RepositoryBase<T, TList> : IRepository<T> where T : class, where TList: class
>>    {
>>        protected readonly ISiriusSqlContext _siriusContext;
>>
>>        protected readonly IDbSet<T> _dbSet;
>>        private readonly IExceptionParser _exceptionParser;
>>
>>        public RepositoryBase(ISiriusSqlContext context)
>>        {
>>            _siriusContext = context;
>>            _dbSet = _siriusContext.Set<T>();
>>            _exceptionParser = new ExceptionParser();
>>            
>>        }
>>
>>
>>Will I be able to do something like this and keep all my current declarations the same as this extra TList class I only want to use when supplied?
>>
>>What are my options here?
>
>Don't see where you're using (or want to use) TList in the above but there shouldn't be a problem. Are you getting one ?

Not yet, as I don't understand what changes do I need to implement in the syntax. As I also said, this class as is already used in our application and I don't want to change all individual calls. My last idea was to create another class based on this one where I would introduce the second class.

Can you help me a bit with the syntax assuming I'll go this route?

Say, here is the current implementation of this class for GuestsRepository:
 public class GuestsRepository : RepositoryBase<Guests>, IGuestsRepository
    {
        public GuestsRepository(ISiriusSqlContext context) : base(context)
        {

        }
For GuestsRepository I want to have another class (GuestsList). For most of the other classes I am OK with the current implementation.
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform