simple-injector

WebApi + Simple Injector + OWIN

天涯浪子 提交于 2019-11-29 06:00:42
I am trying to use SimpleInjector with OWIN in a WebAPI project. However, the following line in ConfigureAuth fails app.CreatePerOwinContext(container.GetInstance<ApplicationUserManager>); The exception is The ApplicationUserManager is registered as 'Web API Request' lifestyle, but the instance is requested outside the context of a Web API Request. I am using container.RegisterWebApiRequest<ApplicationUserManager>(); in container initialization. (there won't be any exceptions if I use Register instead of RegisterWebApiRequest but this is not the preferred method as per simple injector docs )

Does Simple Injector supports MVC 4 ASP.NET Web API?

痞子三分冷 提交于 2019-11-29 03:18:11
I am new to Simple Injector IOC container. I will start working in a project which will require a Multi-tenant ASP.NET MVC implementation using MVC 4 ASP.NET Web API. My question is: Does Simple injector support MVC 4 ASP.NET Web API? Reading simple injector documentation like this makes references to MVC 3 and I would like to know if MVC 4 also is supported. Steven Does Simple injector IOC support MVC 4 ASP.NET Web API? It has currently no support for MVC4 Web API, but support will be added in the future. The integration guide will be updated when this happens. UPDATE : Web API support has

Simple Injector property injection on action filter

╄→гoц情女王★ 提交于 2019-11-29 02:24:37
The action filter I want to inject into starts like this public class UserAuthorisation : AuthorizeAttribute { public IWcfClientProxy<IAppFrameworkServiceChannel> FrameworkServiceProxy { get; set; } I have setup my container like this: container.Register<IWcfClientProxy<IAppFrameworkServiceChannel>>( ()=> new WcfClientProxy<IAppFrameworkServiceChannel>()); container.RegisterInitializer<UserAuthorisation>(handler => { handler.FrameworkServiceProxy = container .GetInstance<IWcfClientProxy<IAppFrameworkServiceChannel>>(); }); When I run this the FrameworkServiceProxy property is null. I have read

Using Simple Injector in Web API and OWIN

半城伤御伤魂 提交于 2019-11-29 01:39:52
I'm experiencing the same problem as described here and my set up is almost identical to this that is actually based on this guide . When I access a method in my controller I get this An error occurred when trying to create a controller of type 'TestController'. Make sure that the controller has a parameterless public constructor. Here's the stack trace at System.Web.Http.Dispatcher.DefaultHttpControllerActivator .Create(HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor, Type controllerType)\r\n at System.Web.Http.Controllers.HttpControllerDescriptor .CreateController

Factory Interface in Simple Injector

夙愿已清 提交于 2019-11-29 00:56:16
问题 I'm a Ninject user that try to learn Simple Injector One Ninject feture that I often use in my applications is the Factory Interface With that I can create a Interface like this: public interface IBarFactory { Bar CreateBar(); } And the register it like this kernel.Bind<IBarFactory>().ToFactory(); Then I simple can use IBarFactory, and don't have to create a implementation of IBarFactory I now try to find anything similar in Simple njector, and have found this. But with that approacher, I

Dependency Injection (using SimpleInjector) and OAuthAuthorizationServerProvider

安稳与你 提交于 2019-11-28 23:19:10
New to Dependency Injection, so this is probably a simple matter, but i have tried and cant figure it out, i am using Simple Injector. I have a WebApi that uses SimpleInjector perfectly fine, now i would like to implement security using OAuth. To do this i started to follow this tutorial, which is very helpful, but doesnt use Dependancy Injection http://bitoftech.net/2014/06/01/token-based-authentication-asp-net-web-api-2-owin-asp-net-identity/ I have my global.asax file looking like this, to setup dependancy injection (working perfect) protected void Application_Start() { SimpleInjectorConfig

Using Application Insights with Unit Tests?

别说谁变了你拦得住时间么 提交于 2019-11-28 21:25:26
I have an MVC web app, and I'm using Simple Injector for DI. Almost all my code is covered by unit tests. However, now that I've added some telemetry calls in some controllers, I'm having trouble setting up the dependencies. The telemetry calls are for sending metrics to the Microsoft Azure-hosted Application Insights service. The app is not running in Azure, just a server with ISS. The AI portal tells you all kinds of things about your application, including any custom events you send using the telemetry library. As a result, the controller requires an instance of Microsoft

Avoiding all DI antipatterns for types requiring asynchronous initialization

梦想的初衷 提交于 2019-11-28 18:15:25
I have a type Connections that requires asynchronous initialization. An instance of this type is consumed by several other types (e.g., Storage ), each of which also require asynchronous initialization (static, not per-instance, and these initializations also depend on Connections ). Finally, my logic types (e.g., Logic ) consumes these storage instances. Currently using Simple Injector. I've tried several different solutions, but there's always an antipattern present. Explicit Initialization (Temporal Coupling) The solution I'm currently using has the Temporal Coupling antipattern: public

ICommandHandler/IQueryHandler with async/await

懵懂的女人 提交于 2019-11-28 18:07:51
问题 EDITH says (tl;dr) I went with a variant of the suggested solution; keeping all ICommandHandler s and IQueryHandler s potentially aynchronous and returning a resolved task in synchronous cases. Still, I don't want to use Task.FromResult(...) all over the place so I defined an extension method for convenience: public static class TaskExtensions { public static Task<TResult> AsTaskResult<TResult>(this TResult result) { // Or TaskEx.FromResult if you're targeting .NET4.0 // with the Microsoft

Simple Injector inject multiple dependency in BaseClass

瘦欲@ 提交于 2019-11-28 12:44:24
问题 I have a BaseViewModel which is inherited by multiple ViewModel classes. In my BaseViewModel I have a couple of dependencies which get injected from ViewModel . Now if I need to add a new dependency in my BaseViewModel I need to change all the VM which inherit BaseViewModel . Please let me know how can it be handled in Simple Injector. Following is my code structure: How can I make my base class injection independent so that I don't need to make changes in all my inherited class? Code: public