yavsc/cli/Program.cs

109 lines
3.4 KiB
C#

7 years ago
using System;
using Microsoft.Extensions.Logging;
using System.Runtime.Versioning;
7 years ago
using Microsoft.AspNet.Builder.Internal;
using Yavsc.Services;
using Google.Apis.Util.Store;
using cli_2;
7 years ago
using Microsoft.Extensions.PlatformAbstractions;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNet.Hosting;
using Yavsc.Models;
using Microsoft.AspNet.Identity.EntityFramework;
using Microsoft.Extensions.OptionsModel;
using Microsoft.AspNet.Hosting.Builder;
7 years ago
using Yavsc;
using Microsoft.AspNet.Hosting.Internal;
7 years ago
public class Program
7 years ago
{
private IServiceProvider serviceProvider;
private static Startup startup;
7 years ago
public Program()
{
ConfigureServices(new ServiceCollection());
}
7 years ago
private void ConfigureServices(IServiceCollection services, string environmentName="Development")
7 years ago
{
IHostingEnvironment hosting = new HostingEnvironment{ EnvironmentName = environmentName };
services.AddLogging();
7 years ago
services.AddOptions();
7 years ago
// Add application services.
services.AddTransient<IEmailSender, MessageSender>();
services.AddTransient<IGoogleCloudMessageSender, MessageSender>();
services.AddTransient<IBillingService, BillingService>();
services.AddTransient<IDataStore, FileDataStore>( (sp) => new FileDataStore("googledatastore",false) );
services.AddTransient<ICalendarManager, CalendarManager>();
// TODO for SMS: services.AddTransient<ISmsSender, AuthMessageSender>();
services.AddLocalization(options =>
{
options.ResourcesPath = "Resources";
});
services.AddIdentity<ApplicationUser,IdentityRole>();
7 years ago
var basePath = AppDomain.CurrentDomain.BaseDirectory;
// FIXME null ref var appName = AppDomain.CurrentDomain.ApplicationIdentity.FullName;
7 years ago
// var rtdcontext = new System.Runtime.DesignerServices.WindowsRuntimeDesignerContext (new string { "." }, "nonname");
7 years ago
serviceProvider = services.BuildServiceProvider();
7 years ago
var projectRoot = "/home/paul/workspace/yavsc/Yavsc";
7 years ago
hosting.Initialize (projectRoot, null);
7 years ago
var targetFramework = new FrameworkName ("dnx",new Version(4,5,1));
//
//
ApplicationEnvironment appEnv = new ApplicationEnvironment(targetFramework, projectRoot);
//configure console logging
// needs a logger factory ...
var loggerFactory = serviceProvider
.GetService<ILoggerFactory>()
.AddConsole(LogLevel.Debug);
7 years ago
startup = new Startup (hosting, appEnv);
startup.ConfigureServices(services);
7 years ago
ApplicationBuilderFactory applicationBuilderFactory
= new ApplicationBuilderFactory(serviceProvider);
var builder = applicationBuilderFactory.CreateBuilder(null);
7 years ago
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);
7 years ago
}
public static void Main(string[] args)
{
Console.WriteLine($"Hello world!" );
foreach (var str in args) {
Console.WriteLine($"*> {str}");
}
startup.Main(args);
}
7 years ago
}