/// <summary> /// The use unity middleware. /// </summary> /// <param name="app"> /// The app. /// </param> /// <param name="container"> /// The container. /// </param> /// <returns> /// The <see cref="IAppBuilder"/>. /// </returns> /// <exception cref="ArgumentNullException"> /// </exception> public static IAppBuilder UseDependencyInjectorMiddleware(this IAppBuilder app, ApplicationDependecyResolver container) { if (app == null) { throw new ArgumentNullException("app"); } // idsvr : remove these guards so that multiple copies of middleware can be registered //if (app.Properties.ContainsKey(MiddlewareRegisteredKey)) return app; app.Use(async(context, next) => { using (var dependencyScope = container.BeginScope()) { context.Set(OwinKeyConstants.ScopedDependencyResolver, dependencyScope); // context.Set(OwinKeyConstants.IdependencyResolver, dependencyScope.GetService(typeof(Interception.Contract.IDependencyResolver))); await next(); } }); //UseMiddlewareFromContainer(app, container); // idsvr : remove these guards so that multiple copies of middleware can be registered //app.Properties.Add(MiddlewareRegisteredKey, true); return(app); }
/// <summary> /// The setup container. /// </summary> protected virtual void SetupContainer() { this.BuildUnityContainer(); var locatorUnityDependencyResolver = new ApplicationDependecyResolver(this.Config.Container); this.DependencyResolver = locatorUnityDependencyResolver; //GlobalConfiguration.Configuration.DependencyResolver = new LocatorUnityDependencyResolver(this.Config.Container); //GlobalConfiguration.Configuration.DependencyResolver = locatorUnityDependencyResolver; // this.Config.Configuration.DependencyResolver = locatorUnityDependencyResolver; // this.Config.Configuration.DependencyResolver = locatorUnityDependencyResolver; }