Created
November 21, 2020 21:36
-
-
Save emrekizildas/28830b07519020fe752a037924fd9c20 to your computer and use it in GitHub Desktop.
Ocelot & Redis Caching on .NET 5.0 API Project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void ConfigureServices(IServiceCollection services) | |
{ | |
services.AddControllers(); | |
services.AddOcelot().AddCacheManager(x => | |
{ | |
x.WithRedisConfiguration("redis", | |
config => | |
{ | |
config.WithAllowAdmin() | |
.WithDatabase(0) | |
.WithEndpoint("localhost", 6379); | |
}) | |
.WithJsonSerializer() | |
.WithRedisCacheHandle("redis"); | |
}); | |
} | |
public async void Configure(IApplicationBuilder app, IWebHostEnvironment env) | |
{ | |
if (env.IsDevelopment()) | |
{ | |
app.UseDeveloperExceptionPage(); | |
} | |
app.UseRouting(); | |
app.UseAuthorization(); | |
app.UseEndpoints(endpoints => | |
{ | |
endpoints.MapControllers(); | |
}); | |
await app.UseOcelot(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment