Search code examples
c#.netasp.net-mvcoopdesign-patterns

Using abstract classes from another assembly in .NET


Let's say I have 3 projects:

  1. Web Project which is in .NET MVC3
  2. Business Logic for the application. Where it is being referenced from the Web Project.
  3. External Project (MyTools) which has some generic functionality like log4Net, nHibernate implementations.

My goal is to implement a particular abstract class which is in the MyTools project in the buisness logic.

public class Client : IEntity //Project Location: Buisness Logic Project
{
    public int Id { get; set; }
    public string Name { get; set; }
}

public class ClientAO : BaseDAO<Client> //Project Location: Buisness Logic Project
{

}

public interface IEntity //Project Location: MyTools Logic Project
{
    int Id { get; set; }
}

public abstract class BaseDAO<TEntity> where TEntity : IEntity, new() //Project      Location: MyTools Logic Project
{
    public static TEntity GetEntityById(int Id)
    {
        //Logic here to get object with ID = id
    }
}

The problem is here: when I try to use ClientAO class, GetEntityById Method is not available in the web project although it is being referenced. Then if I move all the logic in the MyTools project into the business logic without changing anything, GetEntityById will be available. I cannot understand what is happening with this issue. Is there any problem with Access Modifiers? As far as I know setting a class to public, that class can be accessed even from different assembly.


Solution

  • If the proper references are added to your business logic project, this should work.