コード例 #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllersWithViews();
            services.AddRazorPages();
            var apiKey            = Configuration["apiKey"];
            var spoonacularConfig = new SpoonacularConfiguration()
            {
                ApiKey = apiKey
            };

            services.AddSingleton(spoonacularConfig);
            services.AddSingleton <ConcurrentDictionary <int, Recipe> >();
            services.AddHttpClient <ISearchRecipe, RecipeClientWithCache>(client =>
            {
                client.BaseAddress = new Uri("https://api.spoonacular.com/");
            });

            services.AddDbContext <GC_PlanMyMealIdentityDbContext>(options =>
                                                                   options.UseSqlServer(Configuration["ConnectionStrings:PlanMyMealDb"]));

            services.AddScoped <IRepositoryClient, RepositoryClient>();
            services.AddScoped <IPreferencesClient, PreferencesClient>();

            services.AddDefaultIdentity <IdentityUser>(options => options.SignIn.RequireConfirmedAccount = true)
            .AddEntityFrameworkStores <GC_PlanMyMealIdentityDbContext>();
        }
コード例 #2
0
 public RecipeClient(HttpClient httpClient, SpoonacularConfiguration config)
 {
     _httpClient = httpClient;
     _config     = config;
 }
コード例 #3
0
 public RecipeClientWithCache(HttpClient httpClient, SpoonacularConfiguration config, ConcurrentDictionary <int, Recipe> recipeCache) : base(httpClient, config)
 {
     _recipeCache = recipeCache;
 }