Skip to content

Commit

Permalink
fix: seed roles
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlosPavajeau committed Jun 26, 2021
1 parent c9618a2 commit 3e2ebdb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 1 addition & 3 deletions src/Armory.Api/Extensions/Infrastructure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,8 @@ public static IApplicationBuilder ConfigureCors(this IApplicationBuilder app)
return app;
}

public static IApplicationBuilder SeedRoles(this IApplicationBuilder app)
public static IApplicationBuilder SeedRoles(this IApplicationBuilder app, RoleManager<ArmoryRole> roleManager)
{
var roleManager = app.ApplicationServices.GetRequiredService<RoleManager<ArmoryRole>>();

if (!roleManager.RoleExistsAsync("Developer").Result)
{
var developerRole = new ArmoryRole {Name = "Developer"};
Expand Down
6 changes: 4 additions & 2 deletions src/Armory.Api/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Armory.Api.Extensions;
using Armory.Users.Domain;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
Expand All @@ -27,7 +29,7 @@ public void ConfigureServices(IServiceCollection services)
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, RoleManager<ArmoryRole> roleManager)
{
app.ConfigureCors();

Expand All @@ -44,7 +46,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
app.UseAuthentication();
app.UseAuthorization();

app.SeedRoles();
app.SeedRoles(roleManager);

app.UseEndpoints(endpoints => { endpoints.MapControllers(); });
}
Expand Down

0 comments on commit 3e2ebdb

Please sign in to comment.