sepp
sepp
CC#
Created by sepp on 9/18/2023 in #help
❔ Where to store files in N-Tier API Project
Guys I am working on a demo n-tier architecture project I need to implement file uploads and for now I would like to store files locally. Where do you think is the best place to store them? My layers are API, DAL, Services and Entities, or should I create another solution folder called storage?
10 replies
CC#
Created by sepp on 9/18/2023 in #help
✅ Layered architecture EF Core error when creating migrations
I have a Web Api project which is using .NET Core 7, my layers are DAL, Services Entities and API. I recently moved connection string to appsettings.json file (it was hardcoded in my appdbcondext class before) and created a extension method in DAL layer which sets connection string, I am using this in my startup project (API) program.cs but when I run dotnet ef migrations add testMig it gives an error
Unable to create an object of type 'ApplicationDbContext'. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728
Unable to create an object of type 'ApplicationDbContext'. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728
It was not happening when I hard code connection string in DAL layer and add/update migrations, ApplicationDbContext.cs (DAL)
namespace MeetingAppDemo.DAL.Context
{
public class ApplicationDbContext : DbContext
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options)
{
}

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
}
public DbSet<User> Users { get; set; }
public DbSet<Meeting> Meetings { get; set; }
public DbSet<MeetingParticipant> MeetingParticipants { get; set; }
public DbSet<MeetingDocument> MeetingDocuments { get; set; }
}
}
namespace MeetingAppDemo.DAL.Context
{
public class ApplicationDbContext : DbContext
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options)
{
}

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
}
public DbSet<User> Users { get; set; }
public DbSet<Meeting> Meetings { get; set; }
public DbSet<MeetingParticipant> MeetingParticipants { get; set; }
public DbSet<MeetingDocument> MeetingDocuments { get; set; }
}
}
DataAccessExtension.cs (DAL)
namespace MeetingAppDemo.DAL.Extensions
{
public static class DataAccessExtensions
{
public static IServiceCollection SetupDbContext(this IServiceCollection services, string connectionString)
{
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(connectionString));
return services;
}
}
}
namespace MeetingAppDemo.DAL.Extensions
{
public static class DataAccessExtensions
{
public static IServiceCollection SetupDbContext(this IServiceCollection services, string connectionString)
{
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(connectionString));
return services;
}
}
}
Program.cs (API Layer)
// Database Configuration
var dbConnectionString = builder.Configuration.GetConnectionString("Development");
builder.Services.SetupDbContext(dbConnectionString);
// Database Configuration
var dbConnectionString = builder.Configuration.GetConnectionString("Development");
builder.Services.SetupDbContext(dbConnectionString);
8 replies
CC#
Created by sepp on 9/12/2023 in #help
❔ Question about Layered Structure
Guys do you think it is bad to expose Entities Layer both DAL and Services layer? And where should I store my DTOs? My layers are API, DAL, Entities, Services.
5 replies
CC#
Created by sepp on 9/11/2023 in #help
✅ .NET Core N-Tier API Project question about repository pattern.
170 replies
CC#
Created by sepp on 9/6/2023 in #help
❔ Newbie question- dotNET Core API with layered architecture with AngularJS as Frontend
I am creating an application using .NET Core with layered architecture, I have a asked to seperate Model(Entities), API, Context and Web layers AngularJS for frontend. I have created an API using N-Tier architecture before but it was so basic and there was no frontend. I am struggling to create project structure. I have created Bussiness, Data, Entities and API layers but I will need to have users upload files when registering etc. I don't know where I can keep files locally normally in a Node.js app I have two folders for backend and frontend and keep files at backend uploads folder how should I structure this project?
3 replies