Exemplo n.º 1
0
        private void InitializeContainer()
        {
            // Add application services. For instance:
            //   _container.Register<ICommandBus, CommandBus>(Lifestyle.Singleton);
            FrameworkConfigurator.WireUp(_container, false, typeof(VehicleAppService).Assembly, typeof(GetVehicleCurrentPositionQuery).Assembly);
            AppServiceConfigurator.WireUp(_container);
            _container.Register <ICurrentUserService, CurrentUserService>();
            _container.Register <IHttpContextAccessor, HttpContextAccessor>();
            _container.Register <IDataSeeder, DataSeeder>();


            //options.UseSqlServer(
            //       configuration.GetConnectionString("FRIQuery"),
            //       b => b.MigrationsAssembly(typeof(VehicleDbContext).Assembly.FullName)));

            //var reg = Lifestyle.Scoped.CreateRegistration(() =>
            //{
            //    return new VehicleDbContext(new DbContextOptionsBuilder<VehicleDbContext>().UseSqlServer(_configuration.GetConnectionString("FRIQuery")).Options);
            //}, _container);

            var reg = Lifestyle.Scoped.CreateRegistration(() =>
            {
                return(new VehicleDbContext(new DbContextOptionsBuilder <VehicleDbContext>().UseSqlServer(_appSettings.ConnectionStrings.ConnectionString, x => x.UseNetTopologySuite()).Options));
            }, _container);

            _container.AddRegistration <IDbContext>(reg);
            //_container.Register<IDbContext>(() =>
            //{
            //    return new VehicleDbContext(new DbContextOptionsBuilder<VehicleDbContext>().UseSqlServer(_configuration.GetConnectionString("FRIQuery")).Options);
            //});
        }
        static void Main(string[] args)
        {
            string conStr = ConfigurationManager.ConnectionStrings["FRI"].ToString();

            container = new Container();

            container.Options.DefaultScopedLifestyle = new AsyncScopedLifestyle();
            FrameworkConfigurator.WireUp(container, false, typeof(LoanAppService).Assembly, typeof(CreateLoanCommand).Assembly);
            AppServiceConfigurator.WireUp(container);
            //var mydb = new FRIDbContext(conStr);
            //mydb.Database.Migrate();


            var host = new WebHostBuilder()
                       .UseContentRoot(Directory.GetCurrentDirectory())
                       .UseKestrel()
                       .UseStartup <Startup>()
                       .UseUrls("http://localhost:5005/")
                       .Build();


            host.Run();
        }
        private void InitializeContainer()
        {
            // Add application services. For instance:
            //   _container.Register<ICommandBus, CommandBus>(Lifestyle.Singleton);
            FrameworkConfigurator.WireUp(_container, false, typeof(LoanAppService).Assembly, typeof(CreateLoanCommand).Assembly);
            AppServiceConfigurator.WireUp(_container);


            // options.UseSqlServer(
            ////        configuration.GetConnectionString("FRIQuery"),
            ////        b => b.MigrationsAssembly(typeof(FRIDbContext).Assembly.FullName)));

            var reg = Lifestyle.Scoped.CreateRegistration(() =>
            {
                return(new FRIDbContext(new DbContextOptionsBuilder <FRIDbContext>().UseSqlServer(_configuration.GetConnectionString("FRIQuery")).Options));
            }, _container);

            _container.AddRegistration <IDbContext>(reg);
            //_container.Register<IDbContext>(() =>
            //{
            //    return new FRIDbContext(new DbContextOptionsBuilder<FRIDbContext>().UseSqlServer(_configuration.GetConnectionString("FRIQuery")).Options);
            //});
        }