1
1
namespace EasyCaching . Demo . Interceptors
2
2
{
3
+ using EasyCaching . Core ;
3
4
using EasyCaching . Demo . Interceptors . Services ;
4
5
using EasyCaching . Interceptor . AspectCore ;
5
6
using EasyCaching . Interceptor . Castle ;
@@ -22,81 +23,93 @@ public Startup(IConfiguration configuration)
22
23
23
24
public IConfiguration Configuration { get ; }
24
25
25
- //// 1.AspectCore
26
- // public IServiceProvider ConfigureServices(IServiceCollection services)
27
- // {
28
- // services.AddScoped<IAspectCoreService, AspectCoreService>();
26
+ //1.AspectCore
27
+ public IServiceProvider ConfigureServices ( IServiceCollection services )
28
+ {
29
+ services . AddScoped < IAspectCoreService , AspectCoreService > ( ) ;
29
30
30
- // services.AddDefaultInMemoryCache();
31
- // //services.AddDefaultRedisCache(options =>
32
- // //{
33
- // // options.DBConfig = new RedisDBOptions { Configuration = "localhost" };
34
- // //});
31
+ services . AddEasyCaching ( options=>
32
+ {
33
+ options . UseInMemory ( ) ;
35
34
36
- // services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
35
+ //options.UseRedis(config =>
36
+ //{
37
+ // config.DBConfig = new RedisDBOptions { Configuration = "localhost" };
38
+ //});
39
+ } ) ;
37
40
38
- // //1.1. all default
39
- // return services.ConfigureAspectCoreInterceptor();
41
+ services . AddMvc ( ) . SetCompatibilityVersion ( CompatibilityVersion . Version_2_1 ) ;
40
42
41
- // //1.2. default and customize
42
- // //Action<IServiceContainer> action = x =>
43
- // //{
44
- // // x.AddType<IAspectCoreService, AspectCoreService>();
45
- // //};
43
+ //1.1. all default
44
+ return services . ConfigureAspectCoreInterceptor ( ) ;
46
45
47
- // //return services.ConfigureAspectCoreInterceptor(action);
46
+ //1.2. default and customize
47
+ //Action<IServiceContainer> action = x =>
48
+ //{
49
+ // x.AddType<IAspectCoreService, AspectCoreService>();
50
+ //};
48
51
49
- // //1.3. all customize
50
- // //Action<IServiceContainer> action = x =>
51
- // //{
52
- // // x.AddType<IDateTimeService, DateTimeService>();
53
- // // x.Configure(config =>
54
- // // {
55
- // // config.Interceptors.AddTyped<EasyCachingInterceptor>(method => typeof(Core.Internal.IEasyCaching).IsAssignableFrom(method.DeclaringType));
56
- // // });
57
- // //};
52
+ //return services.ConfigureAspectCoreInterceptor(action);
58
53
59
- // //return services.ConfigureAspectCoreInterceptor(action, true);
60
- //}
54
+ //1.3. all customize
55
+ //Action<IServiceContainer> action = x =>
56
+ //{
57
+ // x.AddType<IDateTimeService, DateTimeService>();
58
+ // x.Configure(config =>
59
+ // {
60
+ // config.Interceptors.AddTyped<EasyCachingInterceptor>(method => typeof(Core.Internal.IEasyCaching).IsAssignableFrom(method.DeclaringType));
61
+ // });
62
+ //};
61
63
62
- //2. Castle
63
- public IServiceProvider ConfigureServices ( IServiceCollection services )
64
- {
65
- services . AddMvc ( ) ;
64
+ //return services.ConfigureAspectCoreInterceptor(action, true);
65
+ }
66
66
67
- services . AddTransient < ICastleService , CastleService > ( ) ;
67
+ ////2. Castle
68
+ //public IServiceProvider ConfigureServices(IServiceCollection services)
69
+ //{
70
+ // services.AddTransient<ICastleService, CastleService>();
68
71
69
- services . AddDefaultInMemoryCache ( ) ;
72
+ // services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
73
+
74
+ // services.AddEasyCaching(options =>
75
+ // {
76
+ // options.UseInMemory();
70
77
71
- //2.1. all default
72
- return services . ConfigureCastleInterceptor ( ) ;
78
+ // //options.UseRedis(config =>
79
+ // //{
80
+ // // config.DBConfig = new RedisDBOptions { Configuration = "localhost" };
81
+ // //});
82
+ // });
73
83
74
- //2.2. default and customize
75
- //Action<ContainerBuilder> action = x =>
76
- //{
77
- // x.RegisterType<CastleService>().As<ICastleService>();
78
- //};
84
+ // //2.1. all default
85
+ // return services.ConfigureCastleInterceptor();
79
86
80
- //return services.ConfigureCastleInterceptor(action);
87
+ // //2.2. default and customize
88
+ // //Action<ContainerBuilder> action = x =>
89
+ // //{
90
+ // // x.RegisterType<CastleService>().As<ICastleService>();
91
+ // //};
81
92
82
- //2.3. all customize
83
- //Action<ContainerBuilder> action = x =>
84
- //{
85
- // x.RegisterType<DateTimeService>().As<IDateTimeService>();
93
+ // //return services.ConfigureCastleInterceptor(action);
86
94
87
- // var assembly = Assembly.GetExecutingAssembly();
88
- // x.RegisterType<EasyCachingInterceptor>();
95
+ // //2.3. all customize
96
+ // //Action<ContainerBuilder> action = x =>
97
+ // //{
98
+ // // x.RegisterType<DateTimeService>().As<IDateTimeService>();
89
99
90
- // x.RegisterAssemblyTypes(assembly)
91
- // .Where(type => typeof(Core.Internal.IEasyCaching).IsAssignableFrom(type) && !type.GetTypeInfo().IsAbstract)
92
- // .AsImplementedInterfaces()
93
- // .InstancePerLifetimeScope()
94
- // .EnableInterfaceInterceptors()
95
- // .InterceptedBy(typeof(EasyCachingInterceptor));
96
- //};
100
+ // // var assembly = Assembly.GetExecutingAssembly();
101
+ // // x.RegisterType<EasyCachingInterceptor>();
97
102
98
- //return services.ConfigureCastleInterceptor(action, true);
99
- }
103
+ // // x.RegisterAssemblyTypes(assembly)
104
+ // // .Where(type => typeof(Core.Internal.IEasyCaching).IsAssignableFrom(type) && !type.GetTypeInfo().IsAbstract)
105
+ // // .AsImplementedInterfaces()
106
+ // // .InstancePerLifetimeScope()
107
+ // // .EnableInterfaceInterceptors()
108
+ // // .InterceptedBy(typeof(EasyCachingInterceptor));
109
+ // //};
110
+
111
+ // //return services.ConfigureCastleInterceptor(action, true);
112
+ //}
100
113
101
114
public void Configure ( IApplicationBuilder app , IHostingEnvironment env )
102
115
{
0 commit comments