Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9022187
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:26:33+00:00 2026-06-16T05:26:33+00:00

I am trying to create a Generic Task layer (referred to as AppServ in

  • 0

I am trying to create a Generic Task layer (referred to as AppServ in my project) to interact with my Generic Repository. This is my first dive into generics and am having issues with passing a value to a generic method parameter that is within a Generic Class:

The Base App Services class (which is inherited by a specific app serv class and calls the Generic Repository):

public class BaseAppServ<T> : IBaseAppServ<T> where T : class, IEntity, IAuditStamps, ICompanyFacility, new()
{
    private Repository<T> _repository;
    private T _viewModel;
    private AuditStampsViewModel _auditStamps;

    public BaseAppServ(Repository<T> repository)
    {
        _repository = repository;
        _viewModel = new T();
        _auditStamps = new AuditStampsViewModel();
    }

Here is my specific AppServ class (inherits the BaseAppServ)

public class ManageItemsAppServ : BaseAppServ<ManageItemsAppServ>, IEntity, IAuditStamps, ICompanyFacility
    {

        public ManageItemsAppServ()
            : base(CallBaseConstructor())
            {

            }

            public static Repository<Item> CallBaseConstructor()
            {
                return new Repository<Item>(new InventoryMgmtContext());
            }

I am having issues in the constructor or ManageItemsAppServ, specifically in the base(CallBaseConstructor()) line. It gives an error of:

Argument 1: cannot convert from 'OTIS.Data.Repository<OTIS.domain.InventoryMgmt.Item>' to 'OTIS.Data.Repository<OTIS.AppServ.InventoryMgmt.ManageItemsAppServ>'

I think I know why this is happening (because when I inherit the BaseAppServ I am specifying T of type ManageItemsAppServ and that sets the type of T for the entire BaseAppServ class….right?)

So how do I redefine T for the constructor call which is looking for type Respository?

EDIT:
So I think I need to add a second generic parameter in the BaseAppServ class like (note the U which I constrain to type Repository):

public class BaseAppServ<T, U> where U : Repository<U>, IBaseAppServ<T> where T : class, IEntity, IAuditStamps, ICompanyFacility, new()
    {
        private Repository<U> _repository;
        private T _viewModel;
        private AuditStampsViewModel _auditStamps;

        public BaseAppServ(Repository<U> repository)
        {
            _repository = repository;
            _viewModel = new T();
            _auditStamps = new AuditStampsViewModel();
        }

This seems to be the right path and now the only error is:

Inconsistent accessibility: constraint type 'OTIS.AppServ.IBaseAppServ<T>' is less accessible than 'OTIS.AppServ.BaseAppServ<T,U>'

Which has something to do with the order/syntax of the BaseAppServ class declaration. What should it be?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T05:26:34+00:00Added an answer on June 16, 2026 at 5:26 am

    You’re trying to pass a Repository<Item> as constructor argument where a Repository<ManageItemsAppServ> is expected.

    Note that even if Item inherits from ManageItemsAppServ this is not a valid operation, because generic classes cannot be co- or contravariant.

    So, in short, make sure to pass in the exact type, or to use an interface that is covariant (whether the interface can be covariant depends on the methods on it).

    Edit:

    As per your edit, you probaly want something like this:

    public class BaseAppServ<TModel, TItem>: IBaseAppServ<TModel>
                where TItem : class, IEntity 
                where TModel: ICompanyFacility, new()
    {
        private Repository<TItem> _repository;
        private TModel _viewModel;
        private AuditStampsViewModel _auditStamps;
    
        public BaseAppServ(Repository<TItem> repository)
        {
            _repository = repository;
            _viewModel = new TModel();
            _auditStamps = new AuditStampsViewModel();
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been trying to create a generic event. Basically it should look like this:
I am trying to create a generic list which sorts the items entered into
I am trying to create a generic base repository for my Linq2Sql entities. I'd
I am trying to create a generic typed class, but am running into a
Trying to create a generic video plugin for Expression Engine 2 where I can
I'm trying to create a generic class in PHP that will provide a way
I am trying to create a generic formatter/parser combination. Example scenario: I have a
I am trying to create a generic class which new's up an instance of
I'm trying to create a generic build template for my Makefiles, kind of like
I was trying to create a generic Dictionary that implements IXmlSerializable (credit to Charles

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.