Skip to content

Latest commit

 

History

History

Bet.AspNet.LegacyHosting

Bet.AspNet.LegacyHosting

GitHub license Build status NuGet Nuget feedz.io

Note: Pre-release packages are distributed via feedz.io.

This library provides with a way to register Microsoft.Extensions.DependecyInjection library into the older version of Asp.Net Application in preparation for the migration.

There are many enterprise and small businesses that run their websites from Asp.Net framework and haven't made the transition to AspNetCore. This library attempts to provide with ability for gradual migration of the functionality.

Install

    dotnet add package Bet.AspNet.LegacyHosting

Usage

In Global.asax.cs add the following:

            var builder = WebHost.CreateDefaultBuilder<Global>()
                                .ConfigureServices((context, services) =>
                                {
                                    services.AddOptions<AppOptions>()
                                    .Configure<IConfiguration>((options, config) =>
                                    {
                                        config.Bind("AppOptions", options);
                                    });

                                    // register our service here
                                    services.AddTransient<FeedService>();
                                })
                                .Build();

            // Configure DI for Mvc5 and WebApi2 Controllers
            builder.ConfigureMvcDependencyResolver();

            // Configure DI for WebForms
            builder.ConfigureWebFormsResolver();

Required DotNetCore libraries to be installed on Asp.Net Web Application Project

  • Microsoft.Extensions.Configuration
  • Microsoft.Extensions.Configuration.FileExtensions
  • Microsoft.Extensions.DependencyInjection
  • Microsoft.Extensions.Logging
  • Bet.Extensions.LegacyHosting

Usage within Asp.Net MVC5, WebApi2 or WebForms

        void Application_Start(object sender, EventArgs e)
        {
            var builder = WebHost.CreateDefaultBuilder<Global>()
                                .ConfigureServices((context, services) =>
                                {
                                    services.AddOptions<AppOptions>()
                                    .Configure<IConfiguration>((options, config) =>
                                    {
                                        config.Bind("AppSettings:AppOptions", options);
                                    });

                                    // register our service here
                                    services.AddTransient<FeedService>();
                                })
                                .Build();

            // Configure DI for Mvc5 and WebApi2 Controllers
            builder.ConfigureMvcDependencyResolver();

            // Configure DI for WebForms
            builder.ConfigureWebFormsResolver();

            // Code that runs on application startup
            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
        }
    }

This IHost can also be utilized inside of Owin.