Skip to content

Commit

Permalink
refactor db initializer
Browse files Browse the repository at this point in the history
  • Loading branch information
alimon808 committed Oct 23, 2017
1 parent 53817cc commit fa8b1f4
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 9 deletions.
4 changes: 0 additions & 4 deletions ContosoUniversity.Api/ContosoUniversity.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,4 @@
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />
</ItemGroup>

<ItemGroup>
<Folder Include="Data\" />
</ItemGroup>
</Project>
4 changes: 3 additions & 1 deletion ContosoUniversity.Api/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Microsoft.Extensions.Logging;
using Microsoft.AspNetCore.Rewrite;
using ContosoUniversity.Services;
using ContosoUniversity.Services.Data;

namespace ContosoUniversity.Api
{
Expand Down Expand Up @@ -39,8 +40,9 @@ public Startup(IHostingEnvironment env)
public void ConfigureServices(IServiceCollection services)
{
services.AddCustomizedContext(Configuration, CurrentEnvironment);
services.AddCustomizedIdentity(Configuration);
services.AddCustomizedMvc();

services.AddScoped<IDbInitializer, ApiInitializer>();
}

public void Configure(IApplicationBuilder app, ApplicationContext context, ILoggerFactory loggerFactory, IDbInitializer dbInitializer)
Expand Down
2 changes: 0 additions & 2 deletions ContosoUniversity.Data/SeedData.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using Microsoft.Extensions.Logging;
using ContosoUniversity.Data.Entities;
using System.Linq;
using System.IO;
using Newtonsoft.Json;

namespace ContosoUniversity.Data
{
Expand Down
3 changes: 1 addition & 2 deletions ContosoUniversity.Services/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,10 @@ public static IServiceCollection AddCustomizedContext(this IServiceCollection se
}
}

services.AddScoped<IDbInitializer, DbInitializer>();

services.AddScoped(typeof(IRepository<>), typeof(Repository<>));
services.Configure<SampleData>(configuration.GetSection("SampleData"));


return services;
}

Expand Down
2 changes: 2 additions & 0 deletions ContosoUniversity.Web/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using ContosoUniversity.Services;
using ContosoUniversity.Web.Helpers;
using Microsoft.AspNetCore.Rewrite;
using ContosoUniversity.Services.Data;

namespace ContosoUniversity
{
Expand Down Expand Up @@ -45,6 +46,7 @@ public void ConfigureServices(IServiceCollection services)
services.AddCustomizedIdentity(Configuration);
services.AddCustomizedMessage(Configuration);
services.AddCustomizedMvc();
services.AddScoped<IDbInitializer, WebInitializer>();
services.AddScoped<IModelBindingHelperAdaptor, DefaultModelBindingHelaperAdaptor>();
services.AddScoped<IUrlHelperAdaptor, UrlHelperAdaptor>();
}
Expand Down

0 comments on commit fa8b1f4

Please sign in to comment.