Giter VIP home page Giter VIP logo

runtime-composition's Introduction

Runtime-Composition

Updated version using .NET 8 ASP.NET MVC Core available at:

A C# .NET Framework 4.8 ASP.NET MVC web application demonstrating the concept of run time composition.

The design behind this pattern is that the dependency graph is created during runtime, on a per client request basis. The composition is triggered through the context of the application's operating environment and the information received by the application. Information such as URI, environment variables, server technology, routing, decision trees, machine learning (ML) models, cache, cookies, locale, internet protocol (IP) address, internet service provider (ISP), host operationg system (OS), guest OS, browser, etc... can all be used to compose an application's dependency graph in real-time.

Runtime Composition is enabling a single physical deployment to service many different requirements without the need of having multiple code bases, branches or hosting multiple applications. It's the concept of one physical application acting as several logical applications.

Within the folder App_Start, the main registration for these dependencies are configured in UnityConfig.cs

The code below registers instances with different names. These names are used to call the individual instances throughout the application that have been registered against the interface ILanguage.

container
  .RegisterType<ILanguage, English>("en-GB")
  .RegisterType<ILanguage, Arabic>("ar-SA")
  .RegisterType<ILanguage, Japanese>("jp-JP");

The dependency factory is responsible for resolving and returning the instance as requested during run time of the application.

container.RegisterFactory<Func<string, ILanguage>>(l => new Func<string, ILanguage>(name => l.Resolve<ILanguage>(name)));

The strategy pattern makes the selection during run-time based on the parameter.

    public class HomeController : Controller
    {
        private readonly Func<string, ILanguage> _language;

        public HomeController(Func<string, ILanguage> language)
        {
            _language = language;
        }

        public ActionResult Language(string languageSelect)
        {
            var lang = _language(languageSelect);

            var model = new IndexModel { Message = lang.Message };

            return View("Index", model);
        }
    }

runtime-composition's People

Contributors

shirazadam avatar dependabot[bot] avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.