WEB API: How to pass value from ActionFilter to Repository
By : Aldo Daniel
Date : March 29 2020, 07:55 AM
it should still fix some issue I finnaly made it. For first I write Extension method for IHTTPController like this: code :
public static void SetCredentialsToRepository(this IHttpController controller, string technician, string secret);
public void SetCredentialsToRepository(string technician, string secret)
{
_repository.SetCredentials(technician, secret);
}
actionContext.ControllerContext.Controller.SetCredentialsToRepository(username, secret);
|
How to inject EntityFramework Core DbContext in Repository
By : stuartb3502
Date : March 29 2020, 07:55 AM
around this issue I was wrong about the issue, it wasn't an IoC and DbContext issue. Seems like it was in the .NET platform itself https://github.com/dotnet/corefx/issues/9846#issuecomment-274707732 code :
<dependentAssembly>
<assemblyIdentity name="System.ComponentModel.TypeConverter" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.0.0" />
</dependentAssembly>
|
Asp.Net core ActionFilter - how to pass varying number of parameters
By : user7950628
Date : March 29 2020, 07:55 AM
this one helps. Close but no cigar. You are calling your filter with the wrong parameters. You already are calling it as a TypeFilterAttribute, since you need DI and arguments passed in. Now you just need to fix your arguments. You want to pass in a string array, but you pass in several strings. code :
[TypeFilter(typeof(AuthorizeFilter),
Arguments = new object[] {
new string[] { PolicyName.CanUpdateModule, PolicyName.CanReadModule }
}
)]
public async Task<IActionResult> PutModule([FromRoute] Guid id, [FromBody] Module module) {
/*do stuff*/
}
public class AuthorizeFilter : ActionFilterAttribute
{
private readonly IAuthorizationService _authService;
private readonly string[] _policyNames;
public AuthorizeFilter(IAuthorizationService authService,string[] policyNames)
{
_authService = authService;
_policyNames = policyNames;
}
/* ... */
}
|
Pass (or inject) some HTML/JS or pass some model to shared Net Core Razor Class Library
By : Matthieu Deparis
Date : March 29 2020, 07:55 AM
will help you There's two possible approaches. First, you can simply call a partial in your layout: code :
<partial name="_HeaderExtra" />
@await RenderSectionAsync("HeaderExtra", required: false)
@section HeaderExtra
{
<!-- add something here -->
}
@section HeaderExtra
{
@await RenderSectionAsync("HeaderExtra", required: false)
<!-- add something here -->
}
|
How to inject DbContext into repository constructor in ASP.NET core
By : mohammed abd elatif
Date : March 29 2020, 07:55 AM
it helps some times AddDbContext adds a DbContext as scoped by default, which would cause problems with the singleton repositories. code :
services.AddScoped<IItemRepository, ItemRepository>();
services.AddScoped<IUserRepository, UserRepository>();
|