© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•10mo ago•
105 replies
Bordin

.NET Api Setup

Hello all,
I just need advice in the setup of my .net project.

I was making it using the typical Unit of work (Repository) architecture where you have a unit of work & services that call unit of work which has a bunch of classes that are repositories.

Anyway, a week ago, someone here advised that because i am using EntityFramework, Unit of work is a bad practice, or not recommended.

So I decided to get rid of unit of work & services. And inject the IRepository class in my apis.
Program.cs:
builder.Services.AddTransient<IUserRepository, UserRepository>();
builder.Services.AddTransient<IUserRepository, UserRepository>();


And this is the repository, i am not declaring dbcontext, it's injected as well
    public class UserRepository(IHttpContextAccessor httpContextAccessor, OnlineShopContext myContext) : Repository<User>(httpContextAccessor, myContext), IUserRepository
    public class UserRepository(IHttpContextAccessor httpContextAccessor, OnlineShopContext myContext) : Repository<User>(httpContextAccessor, myContext), IUserRepository


user controller:
    public class UserController(
        IUserRepository userRepository,
        IHttpContextAccessor httpContextAccessor,
        IConfiguration configuration) : Helper(httpContextAccessor, configuration)
    public class UserController(
        IUserRepository userRepository,
        IHttpContextAccessor httpContextAccessor,
        IConfiguration configuration) : Helper(httpContextAccessor, configuration)


This works fine but
Question is, in unit of work, i had to dispose the context

do i need to do that here
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements
Next page

Similar Threads

❔ Inno Setup ...SetupIconFile
C#CC# / help
3y ago
.Net Api MaxPoolSize
C#CC# / help
3y ago
.NET 6 ASP.NET API [Answered]
C#CC# / help
4y ago
✅ ASP.NET Web API cant be reached: (SOLVED: Setup reverse proxy)
C#CC# / help
3y ago