Jhipster.NET Documentation!
Total Page:16
File Type:pdf, Size:1020Kb
JHipster.NET Release 3.0.0 May 02, 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 Fronts 9 4.1 Angular..................................................9 4.2 React...................................................9 4.3 Vue.js................................................... 10 4.4 Alpha - Xamarin............................................. 10 4.5 Alpha - Blazor.............................................. 12 5 Services 15 5.1 Generating Services........................................... 15 5.2 Extending and Customizing Services.................................. 15 5.3 Automatic Service Registration In DI Container............................ 16 6 DTOs 17 6.1 Using DTOs............................................... 17 7 Repository 19 7.1 QueryHelper............................................... 19 7.2 Add, AddRange, Attach, Update and UpdateRange........................... 19 8 Database 21 8.1 Using database migrations........................................ 21 9 Code Analysis 23 9.1 Running SonarQube by script...................................... 23 9.2 Running SonarQube manually...................................... 23 10 Monitoring 25 11 Security 27 i 11.1 JWT................................................... 27 11.2 Enforce HTTPS............................................. 27 11.3 OAuth2 and OpenID Connect...................................... 28 12 Dependencies Management 31 12.1 Nuget Management........................................... 31 12.2 Caution.................................................. 31 13 Entities auditing 33 13.1 Audit properties............................................. 33 13.2 Audit of generated Entities........................................ 33 13.3 Automatically set properties audit.................................... 34 14 Heroku Deploy 35 14.1 Pre-requisites............................................... 35 14.2 Deploying to Heroku........................................... 35 14.3 Databases................................................. 35 15 Running local Blueprint version for development 37 16 Monolith 39 16.1 Monolith Artictecture.......................................... 39 16.2 Monolith structure............................................ 40 17 Microservices 41 17.1 Microservices Artictecture........................................ 42 ii JHipster.NET, Release 3.0.0 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.0.0 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.0.0 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.0.0 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.0.0 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 Fronts When generating an application, you are able to choose between multiple fronts. 4.1 Angular Angular (commonly referred to as “Angular 2+” or “Angular v2 and above”) is a TypeScript-based open-source web application framework. 4.1.1 Generate your application Call the generator jhipster --blueprints dotnetcore and choose Angular front-choice For further information: Using Angular with JHipster 4.2 React React (also known as React.js or ReactJS) is an open-source, front end, JavaScript library for building user interfaces or UI components. 9 JHipster.NET, Release 3.0.0 4.2.1 Generate your application Call the generator jhipster --blueprints dotnetcore and choose React front-choice For further information: Using React with JHipster 4.3 Vue.js Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web. 4.3.1 Generate your application Call the generator jhipster --blueprints dotnetcore and choose Vue front-choice For further information: Using Vue with JHipster 4.4 Alpha - Xamarin With a C#-shared codebase, developers can use Xamarin tools to write native Android, iOS, and Windows apps with native user interfaces and share code across multiple platforms, including Windows, macOS, and Linux. 4.4.1 Available features • Handle registration and connection. • Sidebar menu to navigate through pages. • Entities and users management. • Auto-generated entity models, services, views and viewmodels. 10 Chapter 4. Fronts JHipster.NET, Release 3.0.0 4.4.2 NuGet requirements • akavache >= 7.1.1 • MvvmCross.Forms >= 7.1.1 • System.ComponentModel.Annotations >= 5.0.0 • System.Net.Http.Json >= 3.2.1 • Xamarin.Forms >= 4.6.0 • Xamarin.Essential >=1.5.3 4.4.3 Why Xamarin Xamarin allows to take advantage of this blueprint. Indeed, it enables to generate a modern cross platform application with both front-end and back-end in C#. 4.4.4 Generate your application Call the generator jhipster --blueprints dotnetcore and choose Xamarin front-choice 4.4.5 Structure Any generated Xamarin application is structured as follows client Namespace.Client.Xamarin.Core - Your core application Models Entities - Generated models Services Entities - Generated services ViewModels Entities - Generated viewmodels Views Entities - Generated views Namespace.Client.Xamarin.Android