예제 #1
0
        public static void AddPersistenceServices(this IServiceCollection services, IAppWeatherConfig appConfig)
        {
            services.AddAutoMapper();

            services.AddDbContext <AppWeatherDbtContext>(optionsBuilder =>
            {
                if (appConfig.IsTesting)
                {
                    optionsBuilder.UseLazyLoadingProxies()
                    .UseInMemoryDatabase("AppWeatherTestDb");
                }
                else
                {
                    // production Db
                    optionsBuilder.UseLazyLoadingProxies()
                    .UseSqlServer(appConfig.DataConnectionString,
                                  options => { options.MigrationsAssembly("AppWeather.Api"); });
                }
            });
        }
        public static void RegisterExternalServicesDependencies(this ContainerBuilder builder, IAppWeatherConfig appWeatherConfig)
        {
            builder
            .RegisterType <GooglePlacesApiService>()
            .As <IGooglePlacesApiService>()
            .InstancePerLifetimeScope();

            builder
            .RegisterInstance(new GooglePlacesApiConfiguration(appWeatherConfig.Bindings))
            .As <IGooglePlacesApiConfiguration>()
            .SingleInstance();

            builder
            .RegisterType <OpenWeatherMapApiService>()
            .As <IOpenWeatherMapApiService>()
            .InstancePerLifetimeScope();

            builder
            .RegisterInstance(new OpenWeatherMapApiConfiguration(appWeatherConfig.Bindings))
            .As <IOpenWeatherMapConfiguration>()
            .SingleInstance();
        }
예제 #3
0
 public Startup(IConfiguration configuration)
 {
     _configuration = new AppWeatherConfig(configuration);
 }
 public static void RegisterApiDependencies(this ContainerBuilder builder, IAppWeatherConfig appWeatherConfig)
 {
     builder.RegisterInstance(appWeatherConfig).As <IAppWeatherConfig>().SingleInstance();
 }