Git Product home page Git Product logo

sulmar-mon-netcore3-group2's Introduction

.NET Core

Struktura projektu

Projekt Opis Technologia
Resources Usługa do zarządzania pojazdami i osobami WebApi
Radio Usługa do obsługi radionadajników Middleware
Navigation Usługa do obsługi nawigacji OWIN
Messaging Usługa do komunikacji między osobami Signal-R
Tracking Usługa do śledzenia pojazdów gRPC

Przydatne komendy CLI

  • dotnet --list-sdks - wyświetlenie listy zainstalowanych SDK
  • dotnet new globaljson - utworzenie pliku global.json
  • dotnet new globaljson --sdk-version {version} - utworzenie pliku global.json i ustawienie wersji SDK
  • dotnet new --list - wyświetlenie listy dostępnych szablonów
  • dotnet new {template} - utworzenie nowego projektu na podstawie wybranego szablonu
  • dotnet new {template} -o {output} - utworzenie nowego projektu w podanym katalogu
  • dotnet restore - pobranie bibliotek nuget na podstawie pliku projektu
  • dotnet build - kompilacja projektu
  • dotnet run - uruchomienie projektu
  • dotnet run {app.dll} - uruchomienie aplikacji
  • dotnet test - uruchomienie testów jednostkowych
  • dotnet run watch - uruchomienie projektu w trybie śledzenia zmian
  • dotnet test - uruchomienie testów jednostkowych w trybie śledzenia zmian
  • dotnet add {project.csproj} reference {library.csproj} - dodanie odwołania do biblioteki
  • dotnet remove {project.csproj} reference {library.csproj} - usunięcie odwołania do biblioteki
  • dotnet new sln - utworzenie nowego rozwiązania
  • dotnet sln {solution.sln} add {project.csproj} - dodanie projektu do rozwiązania
  • dotnet sln {solution.sln} remove {project.csproj} - usunięcie projektu z rozwiązania
  • dotnet publish -c Release -r {platform} - publikacja aplikacji
  • dotnet publish -c Release -r win10-x64 - publikacja aplikacji dla Windows
  • dotnet publish -c Release -r linux-x64 - publikacja aplikacji dla Linux
  • dotnet publish -c Release -r osx-x64 - publikacja aplikacji dla MacOS
  • dotnet add package {package-name} - dodanie pakietu nuget do projektu
  • dotnet remove package {package-name} - usunięcie pakietu nuget do projektu

Protokół HTTP

request:

  GET /customers/index.html HTTP/1.1
  host: www.sulmar.pl
  accept: text/html
  {blank-line}

response:

  200 OK
  content-type: text/html
  
  <html>...</html>

request:

GET api/customers HTTP/1.1
  host: www.sulmar.pl
  accept: application/json
  {blank-line}

response:

  content-type: application/json
  
  {json}

request:

 POST api/customers HTTP/1.1
  host: www.sulmar.pl
  content-type: application/xml
  <xml><customer>...</customer></xml>
  {blank-line}

response:

201 Created

REST API

Akcja Opis
GET Pobierz
POST Utwórz
PUT Zamień
PATCH Zmień częściowo
DELETE Usuń
HEAD Czy zasób istnieje

Konfiguracja

Konfiguracja żródła

 public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
                .ConfigureAppConfiguration((hostingContext, config) =>
                {
                    config.AddXmlFile("appsettings.xml", optional: true,  reloadOnChange: true);
                    config.AddJsonFile("appsettings.json", optional: false,  reloadOnChange: true);
                    config.AddJsonFile($"appsettings.{hostingContext.HostingEnvironment.EnvironmentName}.json", optional: true,  reloadOnChange: true);
                })
                .ConfigureWebHostDefaults(webBuilder =>
                {
                    webBuilder.UseStartup<Startup>();
                });
              }

Wstrzykiwanie opcji

public class VehicleOptions
{
    public int Quantity { get; set; }
}
  • Plik konfiguracyjny appsettings.json
{
  "VehicleOptions": {
    "Quantity": 40
  },
  

Konfiguracja z użyciem interfejsu IOptions

  • Instalacja biblioteki
 dotnet add package Microsoft.Extensions.Options
  • Wstrzykiwanie opcji
public class FakeVehicleService
{
   private readonly VehicleOptions options;

    public FakeCustomersService(IOptions<VehicleOptions> options)
    {
        this.options = options.Value;
    }
}
       
        
      public void ConfigureServices(IServiceCollection services)
      {
          services.Configure<VehicleOptions>(Configuration.GetSection("VehicleOptions"));
      }
    }

Konfiguracja bez interfejsu IOptions

  public void ConfigureServices(IServiceCollection services)
        {
            var vehicleOptions = new VehicleOptions();
            Configuration.GetSection("VehicleOptions").Bind(vehicleOptions);
            services.AddSingleton(vehicleOptions);

            services.Configure<VehicleOptions>(Configuration.GetSection("VehicleOptions"));
        }
public class FakeVehicleService
{
   private readonly VehicleOptions options;

    public FakeCustomersService(VehicleOptions options)
    {
        this.options = options;
    }
}

Web API

Włączenie obsługi XML

 public void ConfigureServices(IServiceCollection services)
 {
     services
         .AddMvc(options => options.RespectBrowserAcceptHeader = true)
         .AddXmlSerializerFormatters();
 }

Przekazywanie formatu poprzez adres URL

// GET api/customers/10
// GET api/customers/10.json
// GET api/customers/10.xml

[Route("api/[controller]")]
public class CustomersController : ControllerBase
{
    [FormatFilter]
    [HttpGet("{id:int}.{format?}")]
    public IActionResult GetById(int id)
    {
        if (!customerRepository.IsExists(id))
            return NotFound();

        var customer = customerRepository.Get(id);

        return Ok(customer);
    }
}

Mapowanie encji

EF Core

Interceptors

https://docs.microsoft.com/pl-pl/ef/core/what-is-new/ef-core-3.0/#interception-of-database-operations

sulmar-mon-netcore3-group2's People

Contributors

dependabot[bot] avatar sulmar avatar

Watchers

 avatar

Forkers

pioniak

sulmar-mon-netcore3-group2's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.