OneDeveloper
OneDeveloper
CC#
Created by Metalkon on 9/1/2023 in #help
❔ Entity Framework Migration Issues
Set the api as start up project And then try migration command and also select project in the default project dropdown
3 replies
CC#
Created by OneDeveloper on 5/27/2023 in #help
✅ Generic DI in minimal APIs
$codegif
34 replies
CC#
Created by OneDeveloper on 5/27/2023 in #help
✅ Generic DI in minimal APIs
Thanks for the tip
34 replies
CC#
Created by OneDeveloper on 5/27/2023 in #help
✅ Generic DI in minimal APIs
Cool
34 replies
CC#
Created by OneDeveloper on 5/27/2023 in #help
✅ Generic DI in minimal APIs
Okay Thanks!!
34 replies
CC#
Created by OneDeveloper on 5/27/2023 in #help
✅ Generic DI in minimal APIs
I am using Extension Method
34 replies
CC#
Created by OneDeveloper on 5/27/2023 in #help
✅ Generic DI in minimal APIs
But this is in another static class
34 replies
CC#
Created by OneDeveloper on 5/27/2023 in #help
✅ Generic DI in minimal APIs
public static IServiceCollection AddApplication(this IServiceCollection services) { services.AddMediatR(config => config.RegisterServicesFromAssembly(typeof(DependencyInjection).Assembly)); //builder.Services.AddMediatR(config => config.RegisterServicesFromAssemblyContaining<Program>()); services.AddAutoMapper(typeof(DependencyInjection)); services.AddValidatorsFromAssembly(Assembly.GetExecutingAssembly()); services.AddScoped(typeof(IPipelineBehavior<,>), typeof(ValidationBehavior<,>)); return services; }
34 replies
CC#
Created by OneDeveloper on 5/27/2023 in #help
✅ Generic DI in minimal APIs
This is my program.cs
34 replies
CC#
Created by OneDeveloper on 5/27/2023 in #help
✅ Generic DI in minimal APIs
using CQRS.Api; using CQRS.Api.Controllers; using CQRS.Application; using CQRS.Contracts; using CQRS.Infrastructure; var builder = WebApplication.CreateBuilder(args); var Services = builder.Services; #region Configure Services Services.AddControllers(); Services.AddScoped<RequestPayload>(); Services.AddApplication() .AddInfrastructure(builder.Configuration); #endregion var app = builder.Build(); #region Configure Global Exception Handling app.UseExceptionHandler("/error"); //app.UseExceptionHandler(ex => //{ // ex.Run(async context => // { // context.Response.StatusCode = StatusCodes.Status500InternalServerError; // context.Response.ContentType = "text/plain"; // Exception? exception = context.Features.Get<IExceptionHandlerFeature>()?.Error; // var requestPayload = context.RequestServices.GetRequiredService<RequestPayload>(); // var respose = new ApiResponse(requestPayload: requestPayload, // statusCode: StatusCodes.Status500InternalServerError, // message: "An unexpected error Occurred", // response: exception.Message); // await context.Response.WriteAsJsonAsync(respose); // }); //}); #endregion #region Configure Pipeline & Middleware app.UseMiddleware<Middleware>(); app.UseHttpsRedirection(); app.UseAuthentication(); app.UseAuthorization(); #endregion #region Configure COntrollers & Minimal APIs app.MapControllers(); //Minimal API for Register/Login app.MapAuthEndpoints(); //using (var scope = app.Services.CreateScope()) //{ // var service = scope.ServiceProvider.GetRequiredService<AuthController>(); // service.MapAuthEndpoints(app); //} #endregion app.Run();
34 replies
CC#
Created by OneDeveloper on 5/27/2023 in #help
✅ Generic DI in minimal APIs
Tried this. This one also gives the same error
34 replies
CC#
Created by OneDeveloper on 5/27/2023 in #help
✅ Generic DI in minimal APIs
public static void MapAuthEndpoints(this WebApplication app) { using var scope = app.Services.CreateScope(); IMediator mediator = scope.ServiceProvider.GetRequiredService<IMediator>(); RequestPayload requestPayload = scope.ServiceProvider.GetRequiredService<RequestPayload>(); var auth = app.MapGroup("auth"); auth.MapPost("login", async (HttpContext context, LoginRequest loginRequest) => { var response = await mediator.Send(new LoginCommand(loginRequest)); return new ApiResponse(requestPayload: requestPayload, statusCode: context.Response.StatusCode, response: response); }); auth.MapGet("role/{id:Guid}",GetRoleAsync); }
34 replies
CC#
Created by OneDeveloper on 5/27/2023 in #help
✅ Generic DI in minimal APIs
in program.cs
34 replies
CC#
Created by OneDeveloper on 5/27/2023 in #help
✅ Generic DI in minimal APIs
{ "statusCode": 500, "message": "An error Occurred", "requestDuration": "776 ms", "response": "Cannot access a disposed object.\r\nObject name: 'IServiceProvider'." }
34 replies
CC#
Created by OneDeveloper on 5/27/2023 in #help
✅ Generic DI in minimal APIs
But it gives IServiceProvider is disposed error
34 replies
CC#
Created by OneDeveloper on 5/27/2023 in #help
✅ Generic DI in minimal APIs
using (var scope = app.Services.CreateScope()) { var service = scope.ServiceProvider.GetRequiredService<AuthController>(); service.MapAuthEndpoints(app); } I tried like this
34 replies
CC#
Created by OneDeveloper on 5/27/2023 in #help
✅ Generic DI in minimal APIs
This one i have tried
34 replies
CC#
Created by OneDeveloper on 5/27/2023 in #help
✅ Generic DI in minimal APIs
Can we do it somewhere once like we were doing in Controller based method
34 replies
CC#
Created by OneDeveloper on 5/27/2023 in #help
✅ Generic DI in minimal APIs
That i have to do for each endpoint
34 replies
CC#
Created by V0FBU1VM on 5/19/2023 in #help
❔ Upload large files to azure storage!
This should work for large files as well and you can get the progress also from IProgress that UploadAsync() uses. Are you facing any issue??
5 replies