Getting Started

Below you will find the steps to build your first ASP.NET Core app powered by InfinniPlatform.

Let’s start by building a simple “Hello, world!” app.

1. Install .NET Core

2. Create a new ASP.NET Core project:

mkdir myapp
cd myapp
dotnet new web

3. Install InfinniPlatform.Core package:

dotnet add package InfinniPlatform.Core -s https://www.myget.org/F/infinniplatform/ -v 2.3.8-*

4. Create MyHttpService.cs and define an HTTP service:

MyHttpService.cs
 using System.Threading.Tasks;

 using InfinniPlatform.Http;

 namespace myapp
 {
     class MyHttpService : IHttpService
     {
         public void Load(IHttpServiceBuilder builder)
         {
             builder.Get["/hello"] = async request =>
                 await Task.FromResult("Hello from InfinniPlatform!");
         }
     }
 }

5. Create MyAppContainerModule.cs and register the HTTP service:

MyAppContainerModule.cs
 using InfinniPlatform.Http;
 using InfinniPlatform.IoC;

 namespace myapp
 {
     class MyAppContainerModule : IContainerModule
     {
         public void Load(IContainerBuilder builder)
         {
             builder.RegisterType<MyHttpService>().As<IHttpService>().SingleInstance();
         }
     }
 }

6. Update the code in Startup.cs to use InfinniPlatform:

Startup.cs
 using System;

 using InfinniPlatform.AspNetCore;
 using InfinniPlatform.IoC;

 using Microsoft.AspNetCore.Builder;
 using Microsoft.Extensions.DependencyInjection;

 namespace myapp
 {
     public class Startup
     {
         public IServiceProvider ConfigureServices(IServiceCollection services)
         {
             services.AddContainerModule(new MyAppContainerModule());

             return services.BuildProvider();
         }

         public void Configure(IApplicationBuilder app, IContainerResolver resolver)
         {
             app.UseDefaultAppLayers(resolver);
         }
     }
 }

7. Restore the packages:

dotnet restore -s https://www.myget.org/F/infinniplatform/

8. Run the app (the dotnet run command will build the app when it’s out of date):

dotnet run

9. Browse to http://localhost:5000/hello

10. Press Ctrl+C to stop the app