ASP.NET Core 2 Unable to resolve service for type Microsoft EntityFrameworkCore DbContext

StudentService expects DbContext but the container does not know how to resolve it based on your current startup. You would need to either explicitly add the context to the service collection Startup services.AddScoped<DbContext, SchoolContext>(); services.AddScoped<IStudentService, StudentService>(); Or update the StudentService constructor to explicitly expect a type the container knows how to resolve. StudentService public StudentService(SchoolContext … Read more

ASP.NET 5 Identity – custom SignInManager

I had problems too trying to use a custom SignInManager and turns out to be really easy after all to implement. In Startup.cs, after the default implementation of services.Identity services.AddIdentity<ApplicationUser, IdentityRole>() .AddEntityFrameworkStores<ApplicationDbContext>() .AddDefaultTokenProviders(); You only need to inject into the built-in DI the following: services.AddScoped<SignInManager<MyApplicationUser>, MySignInManager>(); The default SignInManager is overwrited by the custom one.

Has something replaced bundleconfig.json in ASP.NET Core MVC 2.1?

bundleconfig.json was removed from the 2.1 templates because it relied on a tool not created or supported by Microsoft. See https://github.com/aspnet/templating/issues/326. This file [bundleconfig.json] is for configuring the various incantations of the BundlerMinifier tool, which isn’t actually shipped in the templates, or supported by Microsoft. The ASP.NET Core team has replaced bundleconfig with “libman”. Rightclick … Read more

How do I add a parameter to an action filter in asp.net?

The TypeFilterAttribute has an Argument property (of type object[]) where you can pass arguments to the constructor of the implementation. So applied to your example you can use this code: public class MyAttribute : TypeFilterAttribute { public MyAttribute(params string[] ids) : base(typeof(MyAttributeImpl)) { Arguments = new object[] { ids }; } private class MyAttributeImpl : … Read more

Registering a new DelegatingHandler in ASP.NET Core Web API

As already mentioned in previous comment, look into Writing your own middleware Your ApiKeyHandler can be converted into a middleware class that takes in the next RequestDelegate in its constructor and supports an Invoke method as shown: using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Logging; namespace MyMiddlewareNamespace { public class ApiKeyMiddleware { private readonly RequestDelegate _next; private … Read more

Does a Stream get Disposed when returning a File from an Action? [duplicate]

According to source code here aspnet/AspNetWebStack/blob/master/src/System.Web.Mvc/FileStreamResult.cs Yes protected override void WriteFile(HttpResponseBase response) { // grab chunks of data and write to the output stream Stream outputStream = response.OutputStream; using (FileStream) { byte[] buffer = new byte[BufferSize]; while (true) { int bytesRead = FileStream.Read(buffer, 0, BufferSize); if (bytesRead == 0) { // no more data break; … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)