View WeatherForecastController.cs
private static readonly string[] Cities = new[] | |
{ | |
"İstanbul", "Bursa", "Çankırı", "Konya", "Ardahan", "Ordu", "Giresun", "Adana", "Sivas", "İzmir" | |
}; | |
[HttpGet("getforecast/{id}")] | |
public IEnumerable<WeatherForecast> GetForecast(int id) | |
{ | |
List<WeatherForecast> weatherForecasts = new List<WeatherForecast>(); | |
var rng = new Random(); |
View Startup.cs
public void ConfigureServices(IServiceCollection services) | |
{ | |
services.AddControllers(); | |
services.AddOcelot().AddCacheManager(x => | |
{ | |
x.WithRedisConfiguration("redis", | |
config => | |
{ | |
config.WithAllowAdmin() |
View Program.cs
public static IHostBuilder CreateHostBuilder(string[] args) => | |
Host.CreateDefaultBuilder(args) | |
.ConfigureAppConfiguration((host, config) => | |
{ | |
config.AddJsonFile("ocelot.json"); | |
}) | |
.ConfigureWebHostDefaults(webBuilder => | |
{ | |
webBuilder.UseStartup<Startup>(); | |
}); |
View resilientExample.cs
await ResilientTransaction.New(_catalogContext).ExecuteAsync(async () => | |
{ | |
await _catalogContext.SaveChangesAsync(); | |
await _eventLogService.SaveEventAsync(evt, _catalogContext.Database.CurrentTransaction); | |
}); |
View resilientTransaction.cs
public class ResilientTransaction | |
{ | |
private DbContext _context; | |
private ResilientTransaction(DbContext context) => | |
_context = context ?? throw new ArgumentNullException(nameof(context)); | |
public static ResilientTransaction New (DbContext context) => | |
new ResilientTransaction(context); | |
public async Task ExecuteAsync(Func<Task> action) |
View mesajGonder.js
function mesajGonder() { | |
var mesaj = $("#mesaj").val(); | |
var kadi = $("#kadi").val(); | |
if (kadi != "" && mesaj != "") { | |
var tarih = new Date(); | |
var messageKey = firebase.database().ref("chats/").push().key; //Rastgele bir mesaj keyi gönderir. | |
firebase.database().ref("chats/" + messageKey).set({ | |
message: mesaj, | |
from: kadi, | |
tarih: tarih.getTime() |
View exampleservicestartup.cs
services.AddHttpClient<ExampleService>(); |
View namedclientstartup.cs
services.AddHttpClient("example", c => | |
{ | |
c.BaseAddress = new Uri("https://api.example.com/"); | |
c.DefaultRequestHeaders.Add("Accept", "application/json"); | |
c.DefaultRequestHeaders.Add("User-Agent", "HttpClientFactory-Sample"); | |
}); |
View typedclientmodel.cs
public class TypedClientModel : PageModel | |
{ | |
private readonly ExampleService _exampleService; | |
public IEnumerable<User> Users { get; private set; } | |
public bool HasUser => Users.Any(); | |
public bool GetUsersError { get; private set; } |
View exampleservice.cs
public class ExampleService | |
{ | |
public HttpClient Client { get; } | |
public ExampleService(HttpClient client) | |
{ | |
client.BaseAddress = new Uri("https://api.example.com/"); | |
client.DefaultRequestHeaders.Add("Accept","application/json"); | |
client.DefaultRequestHeaders.Add("User-Agent","HttpClientFactory-Sample"); | |
Client = client; |
NewerOlder