1- using System ;
2- using System . Collections . Generic ;
3- using System . Linq ;
4- using System . Threading . Tasks ;
5- using Microsoft . AspNetCore . Hosting ;
6- using Microsoft . Extensions . Configuration ;
1+ using DistributedCache . Infrastructure ;
2+ using DistributedCache . Services ;
3+ using Microsoft . AspNetCore . Builder ;
4+ using Microsoft . Extensions . DependencyInjection ;
75using Microsoft . Extensions . Hosting ;
8- using Microsoft . Extensions . Logging ;
96
10- namespace DistributedCache
7+ var builder = WebApplication . CreateBuilder ( args ) ;
8+
9+ builder . Services . AddControllersWithViews ( ) ;
10+
11+ builder . Services . AddHttpClient ( ) ;
12+
13+ builder . Services . AddStackExchangeRedisCache ( options =>
14+ {
15+ options . Configuration = builder . Configuration . GetSection ( "Redis" ) [ "ConnectionString" ] ;
16+ } ) ;
17+
18+ builder . Services . AddScoped < UserService > ( ) ;
19+ builder . Services . AddScoped < IUserService , CachedUserService > ( ) ;
20+ builder . Services . AddScoped < ICacheUserService , CacheUserService > ( ) ;
21+ builder . Services . AddScoped < ICacheProvider , CacheProvider > ( ) ;
22+ builder . Services . AddScoped < IHttpClient , HttpClient > ( ) ;
23+
24+ var app = builder . Build ( ) ;
25+
26+ if ( ! app . Environment . IsDevelopment ( ) )
1127{
12- public class Program
13- {
14- public static void Main ( string [ ] args )
15- {
16- CreateHostBuilder ( args ) . Build ( ) . Run ( ) ;
17- }
18-
19- public static IHostBuilder CreateHostBuilder ( string [ ] args ) =>
20- Host . CreateDefaultBuilder ( args )
21- . ConfigureWebHostDefaults ( webBuilder =>
22- {
23- webBuilder . UseStartup < Startup > ( ) ;
24- } ) ;
25- }
28+ app . UseExceptionHandler ( "/Home/Error" ) ;
29+ app . UseHsts ( ) ;
2630}
31+
32+ app . UseHttpsRedirection ( ) ;
33+ app . UseStaticFiles ( ) ;
34+
35+ app . UseRouting ( ) ;
36+
37+ app . UseAuthorization ( ) ;
38+
39+ app . MapControllerRoute (
40+ name : "default" ,
41+ pattern : "{controller=Home}/{action=Index}/{id?}" ) ;
42+
43+ app . Run ( ) ;
0 commit comments