# HostApplicationBuilder Support

**URL:** https://talk.remobjects.com/t/hostapplicationbuilder-support/31013
**Category:** Remoting SDK
**Tags:** visual-studio, net
**Created:** [November 16, 2024, 12:00am UTC](https://talk.remobjects.com/t/hostapplicationbuilder-support/31013 "2024-11-16T00:00:26Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![jgyenese](https://talk.remobjects.com/user_avatar/talk.remobjects.com/jgyenese/32/16996_2.png) [@jgyenese](https://talk.remobjects.com/u/jgyenese)
#### Post date: [November 16, 2024, 12:00am UTC](https://talk.remobjects.com/t/hostapplicationbuilder-support/31013/1 "2024-11-16T00:00:26Z")

</div>

The Remoting SDK documentation includes a section on using Host.CreateDefaultBuilder() to configure an ApplicationServer. However, Microsoft has since moved on to using the newer Host.CreateApplicationBuilder() structure in its Visual Studio templates. Is it possible to configure an ApplicationServer using this newer technique?

---

<div class="post-metadata">

### Author: ![EvgenyK](https://talk.remobjects.com/user_avatar/talk.remobjects.com/evgenyk/32/16_2.png) [@EvgenyK](https://talk.remobjects.com/u/EvgenyK)
#### Post date: [November 18, 2024, 8:56am UTC](https://talk.remobjects.com/t/hostapplicationbuilder-support/31013/5 "2024-11-18T08:56:01Z")

</div>

Hi,

You can add the latest `Microsoft.Extensions.Hosting` package to your project and use `CreateApplicationBuilder` instead of `CreateDefaultBuilder` method.

---

<div class="post-metadata">

### Author: ![jgyenese](https://talk.remobjects.com/user_avatar/talk.remobjects.com/jgyenese/32/16996_2.png) [@jgyenese](https://talk.remobjects.com/u/jgyenese)
#### Post date: [November 18, 2024, 5:31pm UTC](https://talk.remobjects.com/t/hostapplicationbuilder-support/31013/7 "2024-11-18T17:31:32Z")

</div>

Thank you for the reply, but I was really wanting to know how we would configure an ApplicationServer and a NetworkServer when the extension methods provided with the SDK are for IHostBuilder.

Specifically, what would replace the following code:

```auto
return Host.CreateDefaultBuilder(args)
    .ConfigureServices((hostContext, services) =>
    {
    })
    .UseApplicationServer(configuration =>
    {
        configuration.ApplicationName = "ROServer1";
        configuration.RodlNamespace = "ROServer1";
    })
    .UseNetworkServer(server =>
    {
        server.Port = 8090;
    })
    .UseConsoleLifetime();

```

Thank you.

---

<div class="post-metadata">

### Author: ![EvgenyK](https://talk.remobjects.com/user_avatar/talk.remobjects.com/evgenyk/32/16_2.png) [@EvgenyK](https://talk.remobjects.com/u/EvgenyK)
#### Post date: [November 19, 2024, 9:30am UTC](https://talk.remobjects.com/t/hostapplicationbuilder-support/31013/8 "2024-11-19T09:30:59Z")

</div>

Hi,

you can use something like

```auto
using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Hosting;
using RemObjects.SDK.Extensions;
using RemObjects.SDK.Server;

namespace ROServer1
{    
    internal static class Program
    {
        public static void Main(string[] args)
        {
            // Please refer to https://docs.remotingsdk.com/Servers/Technologies/ApplicationHost/
            // for more details
            var host = CreateHostBuilder(args)
                .Build();

            host.Run();
        }

        public static HostApplicationBuilder CreateHostBuilder(string[] args)
        {
            HostApplicationBuilder builder = Host.CreateApplicationBuilder(args);
            // Configure services
            // builder.Services....

            builder.UseApplicationServer(configuration =>
            {
                configuration.ApplicationName = "ROServer1";
                configuration.RodlNamespace = "ROServer1";
            })
            .UseNetworkServer(server =>
            {
                server.Port = 8090;
            });
            return builder;
        }
    }
    
    sealed class ServiceWorker : BackgroundService
    {
            private readonly IAppServerEngine _engine;
    
            public ServiceWorker(IAppServerEngine engine)
            {
                    this._engine = engine;
            }
    
            protected override async Task ExecuteAsync(CancellationToken stoppingToken)
            {
                    this._engine.Initialize();
    
                    this._engine.Start();
    
                    try
                    {
                            while (!stoppingToken.IsCancellationRequested)
                            {
                                    await Task.Delay(1000, stoppingToken);
                            }
                    }
                    finally
                    {
                            this._engine.Stop();
                    }
            }
    }
    
    // Extension methods used to configure RO/DA server
    static class HostBuilderExtensions
    {
        public static HostApplicationBuilder UseApplicationServer(this HostApplicationBuilder builder, Action<IAppServerConfiguration> configureDelegate)
        {
            return HostBuilderExtensions.UseApplicationServer<AppServerEngine>(builder, configureDelegate);
        }

        public static HostApplicationBuilder UseApplicationServer<TAppServerEngine>(this HostApplicationBuilder builder, Action<IAppServerConfiguration> configureDelegate)
            where TAppServerEngine : class, IAppServerEngine
        {
            var config = HostExtensions.GetAppServerConfiguration(configureDelegate);

            // Register worker service
            // TODO Make this configurable
            builder.Services.AddHostedService<ServiceWorker>();
    
            // Register base server infrastructure
            builder.Services.AddInfrastructureServices<TAppServerEngine>(config);
    
            // Register Remoting SDK services
            builder.Services.AddApplicationServices();

            return builder;
        }

        public static HostApplicationBuilder UseNetworkServer(this HostApplicationBuilder builder, Action<INetworkServer> configureDelegate)
        {
            return builder.UseNetworkServer<NetworkServer>(configureDelegate);
        }

        public static HostApplicationBuilder UseNetworkServer<TNetworkServer>(this HostApplicationBuilder builder, Action<INetworkServer> configureDelegate)
            where TNetworkServer : class, INetworkServer
        {
            if (configureDelegate is null)
            {
                throw new ArgumentNullException(nameof(configureDelegate));
            }

            builder.Services.AddNetworkServerConfiguration(configureDelegate);            

            return builder;
        }
    }    
}

```

---

<div class="post-metadata">

### Author: ![jgyenese](https://talk.remobjects.com/user_avatar/talk.remobjects.com/jgyenese/32/16996_2.png) [@jgyenese](https://talk.remobjects.com/u/jgyenese)
#### Post date: [November 27, 2024, 1:46am UTC](https://talk.remobjects.com/t/hostapplicationbuilder-support/31013/9 "2024-11-27T01:46:12Z")

</div>

Thank you, that works well.  
Are there any plans to integrate this into RemObjects.SDK.Extensions?

Thanks again!

---

<div class="post-metadata">

### Author: ![RemObjectsSoftware](https://talk.remobjects.com/user_avatar/talk.remobjects.com/remobjectssoftware/32/15947_2.png) [@RemObjectsSoftware](https://talk.remobjects.com/u/RemObjectsSoftware)
#### Post date: [November 28, 2024, 7:07am UTC](https://talk.remobjects.com/t/hostapplicationbuilder-support/31013/16 "2024-11-28T07:07:05Z")

</div>

Logged as [bugs://D19507](https://www.remobjects.com/portal/bugs/?id=D19507).

---

<div class="post-metadata">

### Author: ![RemObjectsSoftware](https://talk.remobjects.com/user_avatar/talk.remobjects.com/remobjectssoftware/32/15947_2.png) [@RemObjectsSoftware](https://talk.remobjects.com/u/RemObjectsSoftware)
#### Post date: [January 28, 2025, 9:51am UTC](https://talk.remobjects.com/t/hostapplicationbuilder-support/31013/17 "2025-01-28T09:51:54Z")

</div>

[bugs://D19507](https://www.remobjects.com/portal/bugs/?id=D19507) was closed as fixed.
