예제 #1
0
        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);
        }
예제 #2
0
        //----------------------------[ 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);
        }
예제 #3
0
 public UCFiles(IStartup startup)
 {
     InitializeComponent();
     _startup = startup;
     vm       = new ViewModelFiles(_startup.GetPreferenceService(), _startup.GetFileService(), _startup.GetRunNuget());
     Load    += UCFilesLoad;
 }
예제 #4
0
        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);
        }
예제 #5
0
 public void RegisterStartup(IStartup startup)
 {
     if (startup == null)
     {
         throw new ArgumentNullException("startup");
     }
     Locator.CurrentMutable.RegisterConstant(startup);
 }
예제 #6
0
        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)));
        }
예제 #7
0
        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));
        }
예제 #9
0
 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();
 }
예제 #10
0
        private void EnsureStartup()
        {
            if (_startup != null)
            {
                return;
            }

            _startup = _hostingServiceProvider.GetRequiredService <IStartup>();
        }
예제 #11
0
        private void _runPlugin()
        {
            IStartup start_ = base._findClass <IStartup>(@"Startup");

            if (null != start_)
            {
                start_._runStart();
            }
        }
예제 #12
0
        public static IAppHostBuilder CreateAppHostBuilder(this IStartup startup)
        {
            if (startup is IAppHostBuilderStartup hostBuilderStartup)
            {
                return(hostBuilderStartup.CreateAppHostBuilder());
            }

            return(AppHost.CreateDefaultBuilder());
        }
예제 #13
0
        public DiContainer Add(IStartup startup)
        {
            if (startups == null)
            {
                throw new InvalidOperationException("Cannot add to an already build container");
            }

            startups.Add(startup);
            return(this);
        }
예제 #14
0
 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;
 }
예제 #15
0
        private static bool HasDependency(IStartup observer, IStartup subject)
        {
            var dependsOn = observer.GetType().GetCustomAttribute <DependsOnAttribute>();

            if (dependsOn == null)
            {
                return(false);
            }

            return(dependsOn.ModuleType == subject.GetType());
        }
예제 #16
0
        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);
        }
예제 #18
0
 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));
        }
예제 #20
0
 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);
 });
예제 #21
0
        //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);
        }
예제 #23
0
 public Handler(Db db, IStartup startup, IConfiguration configuration)
 {
     _db = db;
     if (startup is Startup s)
     {
         this.configuration = s.Configuration;
     }
     else
     {
         this.configuration = configuration;
     }
 }
예제 #24
0
        /// <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);
        }
예제 #25
0
        /// <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));
        }
예제 #26
0
        public static void Main(string[] args)
        {
            var startups = new IStartup[]
            {
                new AutomapperStartup(),
                new CliStatup()
            };

            foreach (var startup in startups)
            {
                startup.Startup(args);
            }
        }
예제 #27
0
 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();
 }
예제 #28
0
        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());
        }
예제 #30
0
        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.");
            }
        }
예제 #31
0
파일: WebHost.cs 프로젝트: akrisiun/Hosting
        private void EnsureStartup()
        {
            if (_startup != null)
            {
                return;
            }

            _startup = _hostingServiceProvider.GetRequiredService<IStartup>();
        }