Exemplo n.º 1
0
        public static IEndpointInstance StartEndpoint(IConfiguration configuration)
        {
            // initialize endpoint
            var configurationManager  = new ConfigurationManager(configuration);
            var endpointInitializer   = new EndpointInitializer(configurationManager);
            var endpointConfiguration = new EndpointConfiguration(configurationManager.NsbEndpointName);

            endpointInitializer.Initialize(endpointConfiguration, false);

            // register components
            if (configurationManager.IsUseFakes)
            {
                endpointConfiguration.RegisterComponents(reg =>
                                                         reg.ConfigureComponent <GitHubApiForTests>(DependencyLifecycle.InstancePerCall));
            }
            else
            {
                endpointConfiguration.RegisterComponents(reg =>
                                                         reg.ConfigureComponent <GitHubApi>(DependencyLifecycle.InstancePerCall));
            }

            endpointConfiguration.RegisterComponents(reg =>
                                                     reg.ConfigureComponent(() => configurationManager, DependencyLifecycle.InstancePerCall));

            // start endpoint
            return(Endpoint.Start(endpointConfiguration).GetAwaiter().GetResult());
        }
Exemplo n.º 2
0
        public void Configure(IApplicationBuilder app, IApplicationLifetime applicationLifetime, ILoggerFactory loggerFactory)
        {
            ////app.UseCors("MyPolicy");

            // initialize endpoint
            var configurationManager  = new ConfigurationManager(this.config);
            var endpointInitializer   = new EndpointInitializer(configurationManager);
            var endpointConfiguration = new EndpointConfiguration(configurationManager.NsbEndpointName);

            endpointInitializer.Initialize(endpointConfiguration, true);
            applicationLifetime.ApplicationStopping.Register(this.OnShutdown);

            // start endpoint
            this.endpointInstance = Endpoint.Start(endpointConfiguration).GetAwaiter().GetResult();

            // initialize validator
            var commentValidator = new CommentValidator();

            // initialize logger
            var legger = loggerFactory.AddLog4Net().CreateLogger("Web");

            app.UseOwin(x => x.UseNancy(opt => opt.Bootstrapper = new Bootstrapper(
                                            this.endpointInstance,
                                            commentValidator,
                                            legger)));
        }
Exemplo n.º 3
0
        protected async Task AsyncOnStart()
        {
            IConfiguration config = new ConfigurationBuilder()
                                    .SetBasePath(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location))
                                    .AddJsonFile("appsettings.host.dev.json", true, true)
                                    .AddJsonFile("appsettings.host.test.json", true, true)
                                    .AddJsonFile("appsettings.host.production.json", true, true)
                                    .Build();

            var configurationManager  = new ConfigurationManager(config);
            var endpointInitializer   = new EndpointInitializer(configurationManager);
            var endpointConfiguration = new EndpointConfiguration(configurationManager.NsbEndpointName);

            // initialize endpoint
            endpointInitializer.Initialize(endpointConfiguration, false);

            // register components
            if (configurationManager.IsUseFakes)
            {
                endpointConfiguration.RegisterComponents(reg =>
                                                         reg.ConfigureComponent <GitHubApiForTests>(DependencyLifecycle.InstancePerCall));
            }
            else
            {
                endpointConfiguration.RegisterComponents(reg =>
                                                         reg.ConfigureComponent <GitHubApi>(DependencyLifecycle.InstancePerCall));
            }

            endpointConfiguration.RegisterComponents(reg =>
                                                     reg.ConfigureComponent(() => configurationManager, DependencyLifecycle.InstancePerCall));

            // start endpoint
            this.endpointInstance = await Endpoint.Start(endpointConfiguration)
                                    .ConfigureAwait(false);
        }