Jhipster.NET Documentation!
Total Page:16
File Type:pdf, Size:1020Kb
JHipster.NET Release 3.1.1 Jul 28, 2021 Introduction 1 Big Picture 3 2 Getting Started 5 2.1 Prerequisites...............................................5 2.2 Generate your first application......................................5 3 Azure 7 3.1 Deploy using Terraform.........................................7 4 Code Analysis 9 4.1 Running SonarQube by script......................................9 4.2 Running SonarQube manually......................................9 5 CQRS 11 5.1 Introduction............................................... 11 5.2 Create your own Queries or Commands................................. 11 6 Cypress 13 6.1 Introduction............................................... 13 6.2 Pre-requisites............................................... 13 6.3 How to use it............................................... 13 7 Database 15 7.1 Using database migrations........................................ 15 8 Dependencies Management 17 8.1 Nuget Management........................................... 17 8.2 Caution.................................................. 17 9 DTOs 19 9.1 Using DTOs............................................... 19 10 Entities auditing 21 10.1 Audit properties............................................. 21 10.2 Audit of generated Entities........................................ 21 10.3 Automatically set properties audit.................................... 22 11 Fronts 23 i 11.1 Angular.................................................. 23 11.2 React................................................... 23 11.3 Vue.js................................................... 24 11.4 Alpha - Xamarin............................................. 24 11.5 Alpha - Blazor.............................................. 26 12 Heroku Deploy 29 12.1 Pre-requisites............................................... 29 12.2 Deploying to Heroku........................................... 29 12.3 Databases................................................. 29 13 MongoDB 31 13.1 Introduction............................................... 31 13.2 Pre-requisites............................................... 31 13.3 Difference with SQL databases..................................... 31 13.4 WIP.................................................... 32 14 Monitoring 33 15 Repository 35 15.1 QueryHelper............................................... 35 15.2 Add, AddRange, Attach, Update and UpdateRange........................... 35 16 Security 37 16.1 JWT................................................... 37 16.2 Enforce HTTPS............................................. 37 16.3 OAuth2 and OpenID Connect...................................... 38 17 Services 41 17.1 Generating Services........................................... 41 17.2 Extending and Customizing Services.................................. 41 17.3 Automatic Service Registration In DI Container............................ 42 18 Running local Blueprint version for development 43 19 Microservices 45 19.1 Microservices Artictecture........................................ 46 20 Monolith 47 20.1 Monolith Artictecture.......................................... 47 20.2 Monolith structure............................................ 48 ii JHipster.NET, Release 3.1.1 Thanks for taking a look at the JHipster.NET documentation. Please use the left hand nav to get around. I would suggest taking a look at introduction first. You can also find lot of information in https://www.jhipster.tech Introduction 1 JHipster.NET, Release 3.1.1 2 Introduction CHAPTER 1 Big Picture JHipster is a well-known platform for generating modern application in java world. JHipster provides a blueprints system that allows to override the default behavior of the generator JHipster.NET is a blueprint that overrides the back-end part, originally generated in spring boot, by back-end in asp.net core. For the front-end all the common language can be used (angular, react, vue.js). In alpha version we also have the possibility to choose either Blazor or Xamarin for the front. This blueprint is an official blueprint of JHipster official-blueprints 3 JHipster.NET, Release 3.1.1 4 Chapter 1. Big Picture CHAPTER 2 Getting Started 2.1 Prerequisites As this is a JHipster blueprint, we expect you have JHipster and its related tools already installed: • Installing JHipster 2.2 Generate your first application Installation of the blueprint npm install -g generator-jhipster-dotnetcore Call the generator jhipster --blueprints dotnetcore After running this command you have few questions to answer, as Application name, authentication mode, client framework etc Once it’s done, you can build and run your application. dotnet run --verbosity normal --project ./src/YourAppName/YourAppName.csproj Your first application is ready and you can now use it with default user like JHipster (admin admin or user user) Ok now you have an application but without entity. JHipster allow you to add entity with cli or with jdl file (add link) JHipster.NET have the same behavior. jhipster entity <entity-name> Or with jdl jhipster import-jdl my_file.jdl 5 JHipster.NET, Release 3.1.1 You can edit jdl with https://start.jhipster.tech/jdl-studio/ You have now an application with CRUD operations on each new entities with potentially link between entities (one- to-one, many-to-one or many-to-many) Default configurations are availables in the generated project. As an example, a docker compose file is generated with monitoring solutions (influxdb telegraf and chronograf or grafana) The repository : https://github.com/jhipster/jhipster-dotnetcore Sample project : https://github.com/jhipster/jhipster-sample-app-dotnetcore 6 Chapter 2. Getting Started CHAPTER 3 Azure 3.1 Deploy using Terraform Currently supports only monolithic app with SQL Server as database (support for other databases are WIP). Terraform scripts will create Azure App Service, Azure SQL Server 3.1.1 Prerequisites 1. Docker installed with docker-compose and have push access to any of the docker repository like docker hub or Azure container registry. 2. Azure CLI installed on your system. Terraform will require it to authenticate in Azure subscription. 3. Terraform CLI installed on your system. 3.1.2 Steps to follow 1. Execute generate app command and select app as Monolithic with Microsoft SQL server as database. Select yes to generate Terraform scripts. (default: is No) use- azure 2. Use docker-compose command to first build the docker image. docker-compose -f docker/app.yml build 1. Tag the image built during the previous step to push to docker repository by using 7 JHipster.NET, Release 3.1.1 docker tag <source-image> <destination-image>:version/tag 1. Push the image to docker hub or any docker service provider by using docker push <destination-image>:version/tag Note: The docker image link and its tag will use as input to Terraform variables. 5. In the generated app folder, change directory to the Terraform folder. cd terraform 1. Login into your Azure CLI by using az login Note: Terraform plan command will work only if the user is authenticated using Azure CLI. 1. Create a file (terraform.tfvars) in the Terraform folder to provide input to the Terraform main script using below content: location="Central US" subscription_id="<your-azure-subscription>" mssql_admin_user="dbUser" mssql_admin_password="Password!12" docker_image="a5ingh/jhipster-dotnetcore-sampleapp" docker_image_tag="0.1" 1. Execute below terraform commands (one by one) to create resources (Azure app service, Azure SQL) and deploy as a docker image to app service: 1. terraform init # to initialize terraform. 2. terraform plan -out "MyAppPlan" # can choose any name instead of MyAppPlan. 3. terraform apply "MyAppPlan" # it will create the resources and then provide you the link to your deployed app as output variable. 2. You can use terraform destroy to delete/remove all the created resources once you are done using it. 8 Chapter 3. Azure CHAPTER 4 Code Analysis 4.1 Running SonarQube by script 1. Run Sonar in container : docker-compose -f ./docker/sonar.yml up -d 2. Wait container was up Run SonarAnalysis.ps1 and go to http://localhost:9001 4.2 Running SonarQube manually 1. Run Sonar in container : docker-compose -f ./docker/sonar.yml up -d 2. Install sonar scanner for .net : dotnet tool install --global dotnet-sonarscanner 1. Run dotnet sonarscanner begin /d:sonar.login=admin /d:sonar.password=admin /k: ,!"YourProject" /d:sonar.host.url="http://localhost:9001" /s:"`pwd`/SonarQube. ,!Analysis.xml" 1. Build your application : dotnet build 2. Publish sonar results : dotnet sonarscanner end /d:sonar.login=admin /d:sonar. password=admin 3. Go to http://localhost:9001 9 JHipster.NET, Release 3.1.1 10 Chapter 4. Code Analysis CHAPTER 5 CQRS 5.1 Introduction CQRS stands for Command Query Responsibility Segregation. You have the possibility to use this pattern thanks to MediatR. When generating your application, you can choose to use CQRS. Enabling it will generate a new layer for your commands and queries called Application. Namespace.Application Commands - Your commands MyEntity - Your entity MyEntityCreateCommand - A command MyEntityCreateCommandHandler - An handler for your command Queries - Your queries MyEntity - Your entity MyEntityGetQuery - A query MyEntityGetQueryHandler - An handler for your query Namespace.Crosscutting Namespace.Domain Namespace.Domain.Services Namespace.Dto Namespace.Infrastructure 5.2 Create your own Queries or Commands In order to create your own commands and/or queries you have to create two classes : • A command/query