1
0
Форкнуть 0
Dependency injection support for ASP.NET Web Forms 4.x
Перейти к файлу
Steve Molloy 85675f4851
Merge pull request #20 from aspnet/retire-repo
Prepare the Repo for archival.
2023-01-20 10:33:17 -08:00
.nuget prototype 2018-04-26 13:41:49 -07:00
src update readme 2018-05-24 10:36:21 -07:00
test/UnityAdapter.Test add unit tests 2018-05-22 16:18:03 -07:00
tools update build system to support signing 2018-05-17 14:26:49 -07:00
.gitattributes init repo 2018-04-24 16:06:46 -07:00
.gitignore init repo 2018-04-24 16:06:46 -07:00
CODE-OF-CONDUCT.md Link Code of Conduct (#16) 2020-04-09 12:53:43 -07:00
License.txt add license file 2018-05-24 10:39:16 -07:00
README.md Prepare the Repo for archival. 2023-01-20 10:32:47 -08:00
WebFormsDependencyInjection.msbuild update build system to support signing 2018-05-17 14:26:49 -07:00
WebFormsDependencyInjection.sln prototype 2018-04-26 13:41:49 -07:00
build.cmd prototype 2018-04-26 13:41:49 -07:00

README.md

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

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.

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. Add the Unity.Container nuget package to your web project.
  2. Add a reference to Microsoft.AspNet.WebFormsDependencyInjection.Unity.dll built by this project in your web project.
  3. 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.