Git Product home page Git Product logo

aspnetwebformsdependencyinjection's Introduction

Introduction

Dependency injection design pattern is widely used in modern applications. It decouples objects to the extent that no client code has to be changed simply because an object it depends on needs to be changed to a different one. It brings you a lot of benefits, like reduced dependency, more reusable code, more testable code, etc. However, it was very difficult to use dependency injection in WebForms application before. This is not an issue in .Net Framework 4.7.2 anymore. Dependency injection is natively supported in WebForms applications.

This project demonstrates building a dependency injection adapter for the Unity IoC container as a point of reference for other adapter authors. Please note that this implementation is for demonstration purposes only and is not being actively maintained.

How to use

  1. Make sure your web project is targeting .NET Framework 4.7.2. You can download .NET Framework 4.7.2 developer pack from here. Check web.config and targetFramework in httpRuntime section should be 4.7.2.
  <system.web>
    <compilation debug="true" targetFramework="4.7.2"/>
    <httpRuntime targetFramework="4.7.2"/>
  </system.web>
  1. Install Microsoft.AspNet.WebFormsDependencyInjection.Unity nupkg in your project.
  2. Open Global.asax and register the types in UnityContainer.
        protected void Application_Start(object sender, EventArgs e)
        {
            var container = this.AddUnity();

            container.RegisterType<ISomeInterface, SomeImplementation>();
        }

How to build

  1. Open a VS developer command prompt
  2. Run build.cmd. This will build Nuget package and run all the unit tests.
  3. All the build artifacts will be under AspNetWebFormsDependencyInjection\bin\Release\ folder.

How to contribute

Information on contributing to this repo is in the Contributing Guide.

aspnetwebformsdependencyinjection's People

Contributors

danroth27 avatar honggit avatar jinhuafei avatar stephenmolloy avatar terrajobst 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.