clean startup
This commit is contained in:
@ -3,22 +3,24 @@
|
||||
|
||||
|
||||
using System;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Runtime.Versioning;
|
||||
using Microsoft.AspNet.Builder.Internal;
|
||||
using Yavsc.Services;
|
||||
using Google.Apis.Util.Store;
|
||||
using cli_2;
|
||||
using Microsoft.Extensions.PlatformAbstractions;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.AspNet.Builder.Internal;
|
||||
using Microsoft.AspNet.Hosting;
|
||||
using Yavsc.Models;
|
||||
using Microsoft.AspNet.Identity.EntityFramework;
|
||||
using Microsoft.Extensions.OptionsModel;
|
||||
using Microsoft.AspNet.Hosting.Builder;
|
||||
|
||||
using Yavsc;
|
||||
using Microsoft.AspNet.Hosting.Internal;
|
||||
using Microsoft.AspNet.Server;
|
||||
|
||||
using Microsoft.AspNet.Identity.EntityFramework;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.OptionsModel;
|
||||
using Microsoft.Extensions.PlatformAbstractions;
|
||||
using Yavsc;
|
||||
using Yavsc.Models;
|
||||
|
||||
using Yavsc.Services;
|
||||
using cli_2;
|
||||
|
||||
public class Program
|
||||
{
|
||||
@ -26,14 +28,20 @@ public class Program
|
||||
private static Startup startup;
|
||||
|
||||
public Program()
|
||||
{
|
||||
{
|
||||
|
||||
ConfigureServices(new ServiceCollection());
|
||||
|
||||
}
|
||||
|
||||
private void ConfigureServices(IServiceCollection services, string environmentName="Development")
|
||||
{
|
||||
|
||||
IHostingEnvironment hosting = new HostingEnvironment{ EnvironmentName = environmentName };
|
||||
|
||||
services.Add(new ServiceDescriptor(typeof(IHostingEnvironment), hosting ));
|
||||
|
||||
|
||||
services.AddLogging();
|
||||
|
||||
services.AddOptions();
|
||||
@ -55,11 +63,11 @@ public class Program
|
||||
|
||||
services.AddIdentity<ApplicationUser,IdentityRole>();
|
||||
var basePath = AppDomain.CurrentDomain.BaseDirectory;
|
||||
// FIXME null ref var appName = AppDomain.CurrentDomain.ApplicationIdentity.FullName;
|
||||
// FIXME null ref var appName = AppDomain.CurrentDomain.ApplicationIdentity.FullName;
|
||||
|
||||
// var rtdcontext = new System.Runtime.DesignerServices.WindowsRuntimeDesignerContext (new string { "." }, "nonname");
|
||||
// var rtdcontext = new WindowsRuntimeDesignerContext (new string [] { "../Yavsc" }, "Yavsc");
|
||||
|
||||
|
||||
|
||||
serviceProvider = services.BuildServiceProvider();
|
||||
|
||||
var projectRoot = "/home/paul/workspace/yavsc/Yavsc";
|
||||
@ -75,23 +83,24 @@ public class Program
|
||||
// needs a logger factory ...
|
||||
var loggerFactory = serviceProvider
|
||||
.GetService<ILoggerFactory>()
|
||||
.AddConsole(LogLevel.Debug);
|
||||
|
||||
startup = new Startup (hosting, appEnv);
|
||||
startup.ConfigureServices(services);
|
||||
.AddConsole(LogLevel.Verbose);
|
||||
startup = new Startup (hosting, appEnv);
|
||||
|
||||
|
||||
|
||||
ApplicationBuilderFactory applicationBuilderFactory
|
||||
= new ApplicationBuilderFactory(serviceProvider);
|
||||
|
||||
var builder = applicationBuilderFactory.CreateBuilder(null);
|
||||
|
||||
startup.ConfigureServices(services);
|
||||
|
||||
|
||||
IOptions<SiteSettings> siteSettings = serviceProvider.GetService(typeof(IOptions<SiteSettings>)) as IOptions<SiteSettings>;
|
||||
builder.ApplicationServices = serviceProvider;
|
||||
IOptions<SiteSettings> siteSettings = serviceProvider.GetService(typeof(IOptions<SiteSettings>)) as IOptions<SiteSettings>;
|
||||
IOptions<SmtpSettings> smtpSettings = serviceProvider.GetService(typeof(IOptions<SmtpSettings>)) as IOptions<SmtpSettings>;
|
||||
|
||||
startup.Configure(builder,siteSettings,smtpSettings);
|
||||
|
||||
|
||||
startup.Configure(builder, loggerFactory, siteSettings, smtpSettings);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -13,6 +13,8 @@ using Microsoft.Extensions.PlatformAbstractions;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using Yavsc.Server.Helpers;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.AspNet.Http;
|
||||
|
||||
public class Startup
|
||||
{
|
||||
@ -30,7 +32,9 @@ public class Startup
|
||||
public static SiteSettings SiteSetup { get; private set; }
|
||||
public static SmtpSettings SmtpSettup { get; private set; }
|
||||
public IConfigurationRoot Configuration { get; set; }
|
||||
public string ConnectionString { get; private set; }
|
||||
public string ConnectionString {
|
||||
get { return DbHelpers.ConnectionString; }
|
||||
private set { DbHelpers.ConnectionString = value; } }
|
||||
public static IdentityOptions AppIdentityOptions { get; private set; }
|
||||
|
||||
public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv)
|
||||
@ -61,8 +65,7 @@ public class Startup
|
||||
// Use this method to add services to the container.
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
System.Console.WriteLine("Configuring services ...");
|
||||
|
||||
services.AddLogging();
|
||||
var siteSettings = Configuration.GetSection("Site");
|
||||
services.Configure<SiteSettings>(siteSettings);
|
||||
var smtpSettings = Configuration.GetSection("Smtp");
|
||||
@ -116,15 +119,18 @@ public class Startup
|
||||
|
||||
|
||||
// Use this method to configure the HTTP request pipeline.
|
||||
public void Configure(IApplicationBuilder builder, IOptions<SiteSettings> siteSettingsOptions, IOptions<SmtpSettings> smtpSettingsOptions)
|
||||
public void Configure(IApplicationBuilder builder, ILoggerFactory loggerFactory, IOptions<SiteSettings> siteSettingsOptions, IOptions<SmtpSettings> smtpSettingsOptions)
|
||||
{
|
||||
System.Console.WriteLine("Configuring application ...");
|
||||
|
||||
|
||||
app = builder.UseIdentity().UseMiddleware<InteractiveConsoleMiddleWare>().Build();
|
||||
var logger = loggerFactory.CreateLogger<Startup>();
|
||||
logger.LogInformation("Configuring application startup ...");
|
||||
|
||||
SiteSetup = siteSettingsOptions.Value;
|
||||
SmtpSettup = smtpSettingsOptions.Value;
|
||||
DbHelpers.ConnectionString = Configuration["Data:DefaultConnection:ConnectionString"];
|
||||
|
||||
logger.LogInformation("done");
|
||||
}
|
||||
|
||||
public void Main(string[] args)
|
||||
@ -132,11 +138,8 @@ public class Startup
|
||||
var dbContext = new ApplicationDbContext();
|
||||
foreach (var user in dbContext.Users) {
|
||||
Console.WriteLine($"UserName/{user.UserName} FullName/{user.FullName} Email/{user.Email} ");
|
||||
} /**/
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -8,4 +8,4 @@
|
||||
"FavIcon": "/favicon.ico",
|
||||
"Icon": "/images/yavsc.png"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"version": "1.0.0-*",
|
||||
"commands": {
|
||||
"run": "run"
|
||||
"run": "cli"
|
||||
},
|
||||
"resource": "Resources/**/*.resx",
|
||||
"buildOptions": {
|
||||
|
Reference in New Issue
Block a user