C#
C#

help

Root Question Message

mer_nam hai bulla rakhta hu kula
mer_nam hai bulla rakhta hu kula11/22/2022
✅ error

this is error
mer_nam hai bulla rakhta hu kula
mer_nam hai bulla rakhta hu kula11/22/2022
mer_nam hai bulla rakhta hu kula
mer_nam hai bulla rakhta hu kula11/22/2022
this is applicationDb file
mer_nam hai bulla rakhta hu kula
mer_nam hai bulla rakhta hu kula11/22/2022
using Microsoft.EntityFrameworkCore;
using Office.DataAccess;
using Office.DataAccess.Repository;
using Office.DataAccess.Repository.IRepository;
using Microsoft.AspNetCore.Identity;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Services.AddControllersWithViews();
builder.Services.AddDbContext<ApplicationDbContext>(options => options.UseSqlServer(
    builder.Configuration.GetConnectionString("DefaultConnection")
    ));
//options => options.SignIn.RequireConfirmedAccount = true
builder.Services.AddDefaultIdentity<IdentityUser>()
    .AddEntityFrameworkStores<ApplicationDbContext>();

builder.Services.AddScoped<IUnitOfWork,UnitOfWork>();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
    app.UseExceptionHandler("/Home/Error");
    // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
    app.UseHsts();
}

app.UseHttpsRedirection();
app.UseStaticFiles();

app.UseRouting();
app.UseAuthentication();;

app.UseAuthorization();

app.MapControllerRoute(
    name: "default",
    pattern: "{controller=Home}/{action=Index}/{id?}");

app.Run();
mer_nam hai bulla rakhta hu kula
mer_nam hai bulla rakhta hu kula11/22/2022
this is program.cs file
Tvde1
Tvde111/22/2022
as I understand it, it cannot create a UnitOfWork because it does not know how to make an Office.DataAccess.ApplicationDbContext
Tvde1
Tvde111/22/2022
but you do register the context successfully
Tvde1
Tvde111/22/2022
the ApplicationDbContext added to the services in Program.cs is 100% Office.DataAccess.ApplicationDbContext?
mer_nam hai bulla rakhta hu kula
mer_nam hai bulla rakhta hu kula11/22/2022
yes
Tvde1
Tvde111/22/2022
delete /bin and /obj and run again? 😬
Tvde1
Tvde111/22/2022
And where is it trying to create a IUnitOfWork?
mer_nam hai bulla rakhta hu kula
mer_nam hai bulla rakhta hu kula11/22/2022
mer_nam hai bulla rakhta hu kula
mer_nam hai bulla rakhta hu kula11/22/2022
here it is invoking applicationDbcontext in unitofwork
Tvde1
Tvde111/22/2022
yeah but usually the error would also show that e.g. a controller requires IUnitOfWork
mer_nam hai bulla rakhta hu kula
mer_nam hai bulla rakhta hu kula11/22/2022
mer_nam hai bulla rakhta hu kula
mer_nam hai bulla rakhta hu kula11/22/2022
here this is the project file see if you can solve
Message Not Public

Sign In and Join Server To See

11/22/2022
Message Not Public

Sign In and Join Server To See

11/22/2022
Message Not Public

Sign In and Join Server To See

11/22/2022
Message Not Public

Sign In and Join Server To See

11/22/2022
Message Not Public

Sign In and Join Server To See

11/22/2022
Tvde1
Tvde111/22/2022
yeah building a repository atop of EF while still exposing its SaveChanges or IQueryable<T> is a pretty bad design pattern. It abstracts nothing and only limits the use of EF
Message Not Public

Sign In and Join Server To See

11/22/2022
Message Not Public

Sign In and Join Server To See

11/22/2022
mer_nam hai bulla rakhta hu kula
mer_nam hai bulla rakhta hu kula11/22/2022
@335123861928542208 @183678031376809984 thanks for input guys but this error is solved+ after posting this question in multiple servers for the error everyone discouraged me for those repository implementation next time I will keep this in mind
Tvde1
Tvde111/22/2022
it's still good to practice and write code :)
ContactFrequently Asked QuestionsJoin The DiscordBugs & Feature RequestsTerms & Privacy