Skip to content

Commit

Permalink
Improvements to the ASP.NET integration package.
Browse files Browse the repository at this point in the history
  • Loading branch information
dotnetjunkie committed Dec 13, 2015
1 parent a06c5bc commit 2ba0031
Show file tree
Hide file tree
Showing 5 changed files with 2,168 additions and 56 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;

namespace SimpleInjector.Integration.AspNet
namespace SimpleInjector
{
internal static class Requires
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ namespace SimpleInjector
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Mvc.Controllers;
using Microsoft.Extensions.DependencyInjection;
using SimpleInjector.Extensions.ExecutionContextScoping;

/// <summary>
/// Extension methods for integrating Simple Injector with ASP.NET applications.
Expand All @@ -38,8 +39,29 @@ public static class SimpleInjectorAspNetIntegrationExtensions
private static readonly Predicate<Type> AllTypes = type => true;

/// <summary>
/// Cross-wires a registration made in the ASP.NET configuration into Simple Injector, to allow
/// that instance to be injected into application components.
/// Wraps an ASP.NET request in a execution context scope.
/// </summary>
/// <param name="applicationBuilder">The ASP.NET application builder instance that references all
/// framework components.</param>
/// <param name="container"></param>
public static void UseSimpleInjector(this IApplicationBuilder applicationBuilder, Container container)
{
Requires.IsNotNull(applicationBuilder, nameof(applicationBuilder));
Requires.IsNotNull(container, nameof(container));

applicationBuilder.Use(async (context, next) =>
{
using (container.BeginExecutionContextScope())
{
await next();
}
});
}

/// <summary>
/// Cross-wires a registration made in the ASP.NET configuration into Simple Injector with the
/// <see cref="Lifestyle.Transient">Transient</see> lifestyle, to allow that instance to be injected
/// into application components.
/// </summary>
/// <typeparam name="TService">The type of the ASP.NET abstraction to cross-wire.</typeparam>
/// <param name="container">The container to cross-wire that registration in.</param>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
#endregion

namespace SimpleInjector
namespace SimpleInjector.Integration.AspNet
{
using System;
using Microsoft.AspNet.Mvc;
Expand All @@ -39,10 +39,7 @@ public class SimpleInjectorControllerActivator : IControllerActivator
/// <param name="container">The container instance.</param>
public SimpleInjectorControllerActivator(Container container)
{
if (container == null)
{
throw new ArgumentNullException(nameof(container));
}
Requires.IsNotNull(container, nameof(container));

this.container = container;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "3.1.2-alpha2",
"version": "3.1.2-alpha3",
"compilationOptions": { "keyFile": "../../SimpleInjector.snk" },
"description": "Integration library for ASP.NET 5 and up for the Simple Injector Inversion of Control library.",
"authors": [ "Simple Injector Contributors" ],
Expand All @@ -23,6 +23,7 @@
},
"dependencies": {
"Microsoft.AspNet.Mvc.Core": "6.0.0-rc1-final",
"SimpleInjector": "3.1.2-alpha2"
"SimpleInjector": "3.1.2-alpha2",
"SimpleInjector.Extensions.ExecutionContextScoping": "3.1.2-alpha2"
}
}
Loading

0 comments on commit 2ba0031

Please sign in to comment.