Ejemplo n.º 1
0
        public static void Main()
        {
            var configurationBuilder = new ConfigurationBuilder()
                                       .SetBasePath(Directory.GetCurrentDirectory())
                                       .AddJsonFile("appsettings.json");
            var configuration = configurationBuilder.Build();

            ServiceRunner <NotificationServiceWrapper> .Run(config =>
            {
                var name = config.GetDefaultName();
                config.Service(serviceConfig =>
                {
                    serviceConfig.ServiceFactory(extraArguments =>
                    {
                        var zeroConfiguration = new ZeroConfiguration();
                        configuration.GetSection("ZeroMq").Bind(zeroConfiguration);
                        var notificationDequeue = new ZeroNotificationDequeue(zeroConfiguration);

                        var identityContextOptionsBuilder = new DbContextOptionsBuilder <ApplicationIdentityContext>();
                        identityContextOptionsBuilder.UseSqlServer(configuration.GetConnectionString("Identity"));

                        var notificationService = new NotificationService(notificationDequeue, identityContextOptionsBuilder.Options);
                        return(new NotificationServiceWrapper(notificationService));
                    });
                    serviceConfig.OnStart((service, extraArguments) =>
                    {
                        Console.WriteLine("Service {0} started", name);
                        service.Start();
                    });

                    serviceConfig.OnStop(service =>
                    {
                        Console.WriteLine("Service {0} stopped", name);
                        service.Stop();
                    });

                    serviceConfig.OnError(e =>
                    {
                        Console.WriteLine("Service {0} errored with exception : {1}", name, e.Message);
                    });
                });
            });

            Console.WriteLine("Press <ENTER> to exit...");
            Console.ReadLine();
        }
Ejemplo n.º 2
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDbContext <ApplicationIdentityContext>(options =>
                                                               options.UseSqlServer(Configuration.GetConnectionString("Identity")));

            services.AddIdentity <ApplicationUser, IdentityRole>()
            .AddEntityFrameworkStores <ApplicationIdentityContext>()
            .AddDefaultTokenProviders();

            services.AddMvc();

            services.AddDbContext <TweetsContext>(options =>
                                                  options.UseSqlServer(Configuration.GetConnectionString("Tweets")));

            services.AddTransient <ITweetsRepository, TweetsRepository>();

            ZeroConfiguration zeroConfiguration = new ZeroConfiguration();

            Configuration.GetSection("ZeroMq").Bind(zeroConfiguration);
            services.AddSingleton <INotificationEnqueue>(provider => new ZeroNotificationEnqueue(zeroConfiguration));
        }