Skip to content

Instantly share code, notes, and snippets.

View dmitry-pavlov's full-sized avatar

Dmitry Pavlov dmitry-pavlov

View GitHub Profile
@{
ViewData["Title"] = "Home Page";
}
<div class="text-center">
<h1 class="display-4">Welcome</h1>
<p>Learn about <a href="https://docs.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p>
<p>We have injected Pet Store to our DI and retrieved data from API.</p>
<ul>
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Samples.AspNetCoreMvc.ClientInjectedToStartup.PetStore
{
/// <summary>This partial class allows to wrap and extend the generated client logic if you need that.</summary>
public partial class Client : IPetStoreClient
{
// Note: let's implement the interface methods we want to expose
public void ConfigureServices(IServiceCollection services)
{
...
// Inject generated PetStore client via using HttpClientFactory to implement resilient HTTP requests.
services.AddHttpClient<IPetStoreClient, Client>((provider, client) =>
{
client.BaseAddress = new System.Uri("https://petstore.swagger.io/v2/");
});
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
public class HomeController : Controller
{
private readonly IPetStoreClient _petStoreClient;
public HomeController(IPetStoreClient petStoreClient)
{
_petStoreClient = petStoreClient;
}
public async Task<IActionResult> Index()
@dmitry-pavlov
dmitry-pavlov / ListToTree.cs
Created March 8, 2019 15:18
Nice & universal way to convert List of items to Tree
using System;
using System.Collections.Generic;
using System.Linq;
using Xunit;
using Xunit.Abstractions;
namespace ListToTree
{
public class Category
{