Skip to content
Jaime Diaz edited this page Jun 3, 2019 · 8 revisions

devon4net Templates Guide

Overview

In this guide we will explain how to generate a new WebApi project from an OpenAPI 3.0.0 specification. This means that we are going to use a “contract first” strategy. This is going to be possible due to these type of files that contain all the information about entities, operations, etc…

In order to make it work we are using CobiGen, a powerful tool for generating source code. CobiGen allows users to generate all the structure and code of the components, helping to save a lot of time otherwise waisted on repetitive tasks.

Getting things ready

devon4net Templates

We are going to use the template of devon4net as a base to generate all the code, so what we have to do now is to download said template using the following steps.

First of all you have to set up all the environment for .NET, you can do this using the following tutorial. Next we are going to create a new folder where we want to have the WebAPI project, lastly we are going to open the terminal there.

Type the following:

dotnet new -i Devon4Net.WebAPI.Template

and then:

dotnet new Devon4NetAPI

OpenAPI File

In order to let CobiGen generate all the files, we first have to make some modifications to our OpenAPI file.

It is obligatory to put the “x-rootpackage” tag to indicate where CobiGen will place the generated files as well as the "x-component" tags for each component, keep in mind that due to CobiGen’s limitations each component must have its own entity.

You can read more information about how to configure your OpenAPI file and a working example here.

Generating files

In order to generate the files we need to follow some simple steps.

First we are going to import our basic devon4net WebAPI Project into Eclipse. to do so open Eclipse with the “eclipse-main.bat” file that can be found in the devon distribution root folder. Once we are inside of Eclipse we go to File > Open projects from file system…​ and, under "Directory", search for your project.

cobigen

Next we copy our OpenAPI file into the root folder of the project.

cobigen

And then we right click on OpenAPI file and then select CobiGen > Generate…​ It will display a window like this:

cobigen

To select all .NET features choose CRUD devon4net Server otherwise you can select only those that interest you.

cobigen

Ones you select all the files that you want to generate, click on the “Finish” button to generate all the source code.

After that, we open a terminal in the [Project_Name]/Devon4Net.Application.WebAPI and then type:

dotnet run

This will deploy our application in our localhost with the port 8081, so when you click here (localhost:8081/swagger) you can see, in swagger, all the services and the data model.

Finishing touches

After generating the files, locate the services created in Devon4Net.Business.Common

cobigen

Once you have find these you have to import them and add them into the AddBusinessCommonDependencyInjectionService method found in Bussiness/Devon4Net.Business.Common/Configuration/BusinessCommonConfiguration.cs

cobigen
Clone this wiki locally