Giter Site home page Giter Site logo

estudo.csharp.marcosrosasage.ddd's Introduction

Repositório apenas para estudo

Uma arquitetura, em ASP.Net Core, baseada nos princípios do DDD

Adaptado para .NET 5

Instrutor:

Referências:




Criar as Pasta com o comando abaixo:

mkdir Api-DDD

cd Api-DDD

Abrir o VS Code

code .

Abrir e criar o diretório src/ (onde ficarão os projetos)

mkdir src

Criar solução

dotnet new sln --name Api

Criar camada de Aplicação

dotnet new webapi -n Application -o src/Api.Application
dotnet sln add src/Api.Application

dotnet build

Criar a Camada de Dominio

dotnet new classlib -n Domain -o src/Api.Domain
dotnet sln add src/Api.Domain

dotnet build

Criar a Camada de Data

dotnet new classlib -n Data -o src/Api.Data
dotnet sln add src/Api.Data

Criar a Camada de Service

dotnet new classlib -n Service -o src/Api.Service
dotnet sln add src/Api.Service

Criar Referências

cd src/

dotnet add Api.Application reference Api.Domain
dotnet add Api.Application reference Api.Service

dotnet add Api.Data reference Api.Domain

dotnet add Api.Service reference Api.Domain
dotnet add Api.Service reference Api.Data

Api.Data - Instalação Pacotes EntityFramework

Para instalar precisar estar dentro do diretório Api.Data

cd Api.Data

dotnet add package Microsoft.EntityFrameworkCore
dotnet add package Microsoft.EntityFrameworkCore.Tools
dotnet add package Microsoft.EntityFrameworkCore.Design
dotnet add package Npgsql.EntityFrameworkCore.PostgreSQL // Não usei MySQL

Para poder rodar comando no CLI, adicionar no arquivo src\Api.Data\Data.csproj

<ItemGroup>
  <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.dotnet " Version="2.0.3" />
</ItemGroup>

Para restaurar todos os pacotes

dotnet restore

Entity Framework Migrations

dotnet ef migrations add Initials

dotnet ef database update

Executar

Acessar a raiz do projeto

Rodar com ouvinte:

dotnet watch --project src/Api.Application run
ou
dotnet watch --project src/Api.Application/Application.csproj run

Apenas rodar

dotnet run --project src/Api.Application
ou
dotnet run --project src/Api.Application/Application.csproj





Anotações

Mapeamento de entidades

public class MyContext : DbContext
{
  protected override void OnModelCreating(ModelBuilder modelBuilder)
  {
      // Forma 1 - Mapear entidade para tabela
      modelBuilder.Entity<UserEntity>(new UserMap().Configure);
      new UserMap().Configure(modelBuilder.Entity<UserEntity>());

      // Forma 2 - Exemplo BALTA
      modelBuilder.ApplyConfiguration(new UserMap());

      // Forma 3 - Varre um determinado assembly para todos os tipos que o implementam IEntityTypeConfiguratione registra cada um automaticamente.
      // Observação: A ordem na qual as configurações serão aplicadas é indefinida,portanto, esse método só deve ser usado quando a ordem não importa.
      modelBuilder.ApplyConfigurationsFromAssembly(Assembly.GetExecutingAssembly());
  }
}

estudo.csharp.marcosrosasage.ddd's People

Contributors

jeanbarcellos avatar

Watchers

 avatar  avatar

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.