I currently do have the following setup these are the different projects
Project.DAL
: Data Access Layer
Project.BLL
: Business Logic Layer
Project.Core
: Interfaces, Models
Project.API
: Web API
Project.Console
: Simple .NET console app that
in Project.DAL
I did setup the db context
public class AppDbContext : DbContext
{
public DbSet<Role> Roles { get; set; }
public DbSet<User> Users { get; set; }
public AppDbContext(DbContextOptions<AppDbContext> options)
: base(options)
{ }
}
while I did setup within Project.API
all the Dependencies Injections
services.AddTransient<IUserService, UserService>();
services.AddDbContext<AppDbContext>(options =>
{
options.UseSqlServer(Configuration.GetConnectionString("Default"),x => x.MigrationsAssembly("Project.DAL"));
});
when I try to run Program.cs
in Project.Console
class Program
{
private static AppDbContext _appDbContext;
static void Main(string[] args)
{
_appDbContext.Users.ToList();
}
}
Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
any idea ?
Thanks In Advance.