public void Configure() { var env = new HostingEnvironment(); var services = new ServiceCollection(); services.AddSingleton <IHostingEnvironment, HostingEnvironment>(); services.AddSingleton <IApplicationLifetime, ApplicationLifetime>(); services.AddSingleton <IApplicationBuilder, ApplicationBuilder>(); services.AddLogging(); IStartup startup = FindAndConstructStartupViaReflection(env); startup.ConfigureServices(services); _serviceProvider = services.BuildServiceProvider(); _logger = _serviceProvider.GetRequiredService <ILogger <ConsoleHost> >(); _applicationBuilder = _serviceProvider.GetRequiredService <IApplicationBuilder>(); _applicationLifetime = _serviceProvider.GetRequiredService <IApplicationLifetime>() as ApplicationLifetime; var loggerFactory = _serviceProvider.GetRequiredService <ILoggerFactory>(); startup.Configure(_applicationBuilder, env, loggerFactory, _applicationLifetime); }
//----------------------------[ Initialization ]------------------ private void init(IStartup startup, Creator viewModelCreator, Creator imageCreator, Creator contextCreator, ModelCreator modelCreator, Creator commandCreator) { _startup = startup; _viewModelCreator = viewModelCreator; _imageCreator = imageCreator; _contextCreator = contextCreator; _modelCreator = modelCreator; _commandCreator = commandCreator; _lang = Thread.CurrentThread.CurrentCulture.Name; _context = _contextCreator.createContext(this); _searchProgressVisibolity = "Visible"; _startup.initialize(); _widthDataList = 1200; _heightDataList = 600; //------[ ViewModels ] ItemViewModel = (IItemViewModel)_viewModelCreator.createViewModel(EViewModel.ITEM, this); ClientViewModel = (IClientViewModel)_viewModelCreator.createViewModel(EViewModel.CLIENT, this); AgentViewModel = (IAgentViewModel)_viewModelCreator.createViewModel(EViewModel.AGENT, this); ChatRoomViewModel = (IChatRoomViewModel)_viewModelCreator.createViewModel(EViewModel.CHAT, this); HomeViewModel = (IHomeViewModel)_viewModelCreator.createViewModel(EViewModel.HOME, this); NotificationViewModel = (INotificationViewModel)_viewModelCreator.createViewModel(EViewModel.NOTIFICATION, this); ReferentialViewModel = (IReferentialViewModel)_viewModelCreator.createViewModel(EViewModel.REFERENTIAL, this); StatisticViewModel = (IStatisticViewModel)_viewModelCreator.createViewModel(EViewModel.STATISTIC, this); OrderViewModel = (IOrderViewModel)_viewModelCreator.createViewModel(EViewModel.ORDER, this); QuoteViewModel = (IQuoteViewModel)_viewModelCreator.createViewModel(EViewModel.QUOTE, this); SecurityLoginViewModel = (ISecurityLoginViewModel)_viewModelCreator.createViewModel(EViewModel.SECURITYLOGIN, this); }
public UCFiles(IStartup startup) { InitializeComponent(); _startup = startup; vm = new ViewModelFiles(_startup.GetPreferenceService(), _startup.GetFileService(), _startup.GetRunNuget()); Load += UCFilesLoad; }
public static Builder Create(IStartup startup, int width, int height) { var builder = new Builder(startup); builder._startup.Engine = builder._startup.CreateEngine(width, height); return(builder); }
public void RegisterStartup(IStartup startup) { if (startup == null) { throw new ArgumentNullException("startup"); } Locator.CurrentMutable.RegisterConstant(startup); }
public static IWebHostBuilder UseStartup(this IWebHostBuilder hostBuilder, IStartup startupInstance) { var typeInfo = startupInstance.GetType().GetTypeInfo(); return(hostBuilder .UseApplicationKey(typeInfo.Assembly.GetName().Name) .ConfigureServices(services => services.AddSingleton(typeof(IStartup), _ => startupInstance))); }
public WinTasksViewModel(IStartup startup, Window window) : base(startup) { _window = window; KillTaskCommand = new ActionCommand <WinTask>(KillTask); Model.OnHotKeyPress += async() => await OnGlobalHookKeyPress(); ((WinTasksView)View).OnTaskKillEvent += async kill => await KillTask(kill); }
protected override IServiceProvider ConfigureApplicationServices(IStartup startup, IServiceCollection serviceCollection) { if (applicationServicesResolver != null) { return(applicationServicesResolver(startup, serviceCollection)); } return(base.ConfigureApplicationServices(startup, serviceCollection)); }
public Host(IStartup startup, IMonitor monitor, IConfiguration configuration, IShutdown shutdown, IComponentFactory factory) { _startup = startup; _monitor = monitor; Configuration = configuration; _shutdown = shutdown; _factory = factory; _cancellationtokensource = new CancellationTokenSource(); }
private void EnsureStartup() { if (_startup != null) { return; } _startup = _hostingServiceProvider.GetRequiredService <IStartup>(); }
private void _runPlugin() { IStartup start_ = base._findClass <IStartup>(@"Startup"); if (null != start_) { start_._runStart(); } }
public static IAppHostBuilder CreateAppHostBuilder(this IStartup startup) { if (startup is IAppHostBuilderStartup hostBuilderStartup) { return(hostBuilderStartup.CreateAppHostBuilder()); } return(AppHost.CreateDefaultBuilder()); }
public DiContainer Add(IStartup startup) { if (startups == null) { throw new InvalidOperationException("Cannot add to an already build container"); } startups.Add(startup); return(this); }
public PluginFinder(IFileManager fileManager, ApplicationPartManager applicationPartManager, IAssemblyLoader assemblyLoader, IHostingEnvironment hostingEnvironment, IServiceProvider serviceProvider, IStartup startup) { _fileManager = fileManager; _applicationPartManager = applicationPartManager; _assemblyLoader = assemblyLoader; _hostingEnvironment = hostingEnvironment; _serviceProvider = serviceProvider; _startup = startup; }
private static bool HasDependency(IStartup observer, IStartup subject) { var dependsOn = observer.GetType().GetCustomAttribute <DependsOnAttribute>(); if (dependsOn == null) { return(false); } return(dependsOn.ModuleType == subject.GetType()); }
public void OnStart(StageArgs args) { _startup = args.TryGetInstance <IStartup>(); if (_startup == null) { throw new StartupNotFoundException(); } _startup.Execute(new ServiceArgs(args.StartArgs, () => false)); }
public SWContainerBuilder UseStartUp <T>() where T : IStartup, new() { startup = new T() as IStartup; startup.ConfigureServices(this); this.RegisterInstance(startup).As <IStartup>(); return(this); }
public static void Init(IStartup startup = null, Action <IServiceCollection> platformBuild = null) => InitPlatform(startup, services => { services.TryAddSingleton <IEnvironment, EnvironmentImpl>(); services.TryAddSingleton <IConnectivity, SharedConnectivityImpl>(); services.TryAddSingleton <IPowerManager, PowerManagerImpl>(); services.TryAddSingleton <IJobManager, JobManagerImpl>(); services.TryAddSingleton <IFileSystem, FileSystemImpl>(); services.TryAddSingleton <ISettings, SettingsImpl>(); platformBuild?.Invoke(services); });
private IServiceProvider CreateServiceProvider <TContainerBuilder>(IStartup startup, IServiceCollection services) { var serviceProviderFactory = _hostingServiceProvider.GetRequiredService <IServiceProviderFactory <TContainerBuilder> >(); var containerBuilder = serviceProviderFactory.CreateBuilder(services); if (startup is IStartup <TContainerBuilder> typedStartup) { typedStartup.ConfigureContainer(containerBuilder); } return(serviceProviderFactory.CreateServiceProvider(containerBuilder)); }
public static void Init(IStartup startup = null, Action <IServiceCollection> platformBuild = null) => InitPlatform(startup, services => { services.AddSingleton <IConnectivity, SharedConnectivityImpl>(); services.AddSingleton <IPowerManager, PowerManagerImpl>(); services.AddSingleton <IJobManager, JobManager>(); services.AddSingleton <IRepository, FileSystemRepositoryImpl>(); services.AddSingleton <IFileSystem, FileSystemImpl>(); services.AddSingleton <ISerializer, JsonNetSerializer>(); services.AddSingleton <ISettings, SettingsImpl>(); platformBuild?.Invoke(services); });
//active when solidworks load our addin public override void ConnectToSWPost(SldWorks swApp) { ContainerBuilder = new SWContainerBuilder(). AddAddin(this, this, iCmdMgr).UseStartUp <Startup>(); Container = ContainerBuilder.Build(); //solve startup from container using (var scope = Container.BeginLifetimeScope()) { _startup = scope.Resolve <IStartup>(); } }
public Microsoft.Extensions.Hosting.IHostBuilder UseStartUp <T>() { System.Type startupType = typeof(T); this.m_hostServices.AddSingleton(typeof(IStartup), startupType); Microsoft.Extensions.Configuration.IConfiguration Configuration = this.m_configurationBuilder.Build(); this.m_hostServices.Configure <Microsoft.Extensions.Configuration.IConfiguration>(Configuration); this.m_hostServices.AddSingleton <Microsoft.Extensions.Configuration.IConfiguration>(Configuration); System.IServiceProvider sp = this.m_hostServices.BuildServiceProvider(); // Microsoft.Extensions.DependencyInjection.IServiceCollection services2 = Clone(this.m_hostServices); this.m_hostBuilder.ConfigureServices( (hostContext, services) => { if (System.Environment.OSVersion.Platform == System.PlatformID.Unix) { services.AddHostedService <LinuxServiceHost>(); } else { // Inject concrete implementation of the service services.AddSingleton(typeof(System.ServiceProcess.ServiceBase), typeof(GenericService)); } } ); this.m_startup = sp.GetRequiredService <IStartup>(); this.m_hostBuilder.ConfigureServices( (hostContext, services) => { services.AddSingleton <IStartup>(this.m_startup); } ); this.m_hostBuilder.ConfigureServices((hostContext, services) => { this.m_startup.ConfigureServices(services); }); this.m_host = this.m_hostBuilder.Build(); this.m_applicationBuilder = new ApplicationBuilder(this.m_host.Services); this.m_startup.Configure(this.m_applicationBuilder); return(this); }
public Handler(Db db, IStartup startup, IConfiguration configuration) { _db = db; if (startup is Startup s) { this.configuration = s.Configuration; } else { this.configuration = configuration; } }
/// <inheritdoc /> public IRuntimeHostBuilder UseStartup(IStartup startup) { if (startup == null) { throw new ArgumentNullException(nameof(startup)); } callbacks.Add(services => services.AddSingleton(typeof(IStartup), (sp) => startup)); startupHasBeenConfigured = true; return(this); }
/// <summary> /// Configures the application services. /// </summary> /// <param name="startup">The startup class handling startup operations.</param> /// <param name="serviceCollection">The collection of services for the application.</param> /// <returns>The service provider containing the application services.</returns> protected virtual IServiceProvider ConfigureApplicationServices(IStartup startup, IServiceCollection serviceCollection) { if (startup == null) { throw new ArgumentNullException(nameof(startup)); } else if (serviceCollection == null) { throw new ArgumentNullException(nameof(serviceCollection)); } return(startup.TryConfigureContainer(serviceCollection)); }
public static void Main(string[] args) { var startups = new IStartup[] { new AutomapperStartup(), new CliStatup() }; foreach (var startup in startups) { startup.Startup(args); } }
public MainWindowViewModel(IStartup startup, Creator viewModelCreator, Creator imageCreator, Creator contextCreator, Creator commandCreator, ModelCreator modelCreator) : base() { createCache(); init(startup, viewModelCreator, imageCreator, contextCreator, modelCreator, commandCreator); CommandInstances(); setInitEvents(); }
public virtual void OnStart(StageArgs args) { _startup = args.TryGetInstance <IStartup>(); if (_startup == null) { throw new StartupNotFoundException(); } _serviceArgs = new ServiceArgs(args.StartArgs, () => _source.IsCancellationRequested); _runner.Start(); }
public static IServiceProvider TryConfigureContainer(this IStartup startupInstance, IServiceCollection services) { if (services == null) { throw new ArgumentNullException(nameof(services)); } var startupType = startupInstance.GetType(); var serviceProvider = services.BuildServiceProvider(); var serviceConfigurator = startupInstance as IConfigureServices; serviceConfigurator?.ConfigureServices(services); var configureMethod = startupType.GetMethod(nameof(IConfigureContainer <object> .ConfigureContainer)); if (configureMethod != null) { var containerBuilderType = configureMethod.GetParameters().Select(o => o.ParameterType).SingleOrDefault(); var providerFactoryType = typeof(IServiceProviderFactory <>).MakeGenericType(containerBuilderType); var configureContainerType = typeof(IConfigureContainer <>).MakeGenericType(containerBuilderType); if (configureContainerType.IsAssignableFrom(startupType)) { var createBuilderMethod = providerFactoryType.GetMethod(nameof(IServiceProviderFactory <object> .CreateBuilder)); if (createBuilderMethod == null) { throw new InvalidOperationException($"The method '{nameof(IServiceProviderFactory<object>.CreateBuilder)}' was not found on the builder factory."); } var providerFactory = serviceProvider.GetService(providerFactoryType); if (providerFactory == null) { throw new InvalidOperationException("The provider factory could not be located on the container. Ensure the service provider factory has been registered."); } var builder = createBuilderMethod.Invoke(providerFactory, new object[] { services }); configureMethod.Invoke(startupInstance, new[] { builder }); var createProviderMethod = providerFactoryType.GetMethod(nameof(IServiceProviderFactory <object> .CreateServiceProvider)); if (createProviderMethod == null) { throw new InvalidOperationException($"The method '{nameof(IServiceProviderFactory<object>.CreateServiceProvider)}' was not found on the provider factory."); } return((IServiceProvider)createProviderMethod.Invoke(providerFactory, new[] { builder })); } } return(services.BuildServiceProvider()); }
void EnsureStartup() { if (_startup != null) { return; } _startup = _hostingServiceProvider.GetService <IStartup>(); if (_startup == null) { throw new InvalidOperationException($"No application configured. Please specify startup via IGameHostBuilder.UseStartup, IGameHostBuilder.Configure, injecting {nameof(IStartup)} or specifying the startup assembly via {nameof(GameHostDefaults.StartupAssemblyKey)} in the game host configuration."); } }
private void EnsureStartup() { if (_startup != null) { return; } _startup = _hostingServiceProvider.GetRequiredService<IStartup>(); }