simple-injector

Register IRestClient with different API URLs with Simple Injector

笑着哭i 提交于 2020-01-17 05:52:12
问题 I would like to register IRestClient with Simple Injector to inject it into a service: public class ActiveCustomersService : IActiveCustomersService { private readonly Uri apiUri = new Uri(string.Format("{0}/{1}", ApiHelper.GetUrl(), thisApiUrl)); private IRestClient _client; public ActiveCustomersService() { _client = new RestClient(apiUri); } public ActiveCustomersService(IRestClient client) { _client = client; } } However when I am trying to register it: private void

When would you need SimpleInjector hybrid registration? (How can an object hosted in IIS be called without a HttpContext?)

我们两清 提交于 2020-01-16 02:05:43
问题 Following on from my recent question regarding SimpleInjector and hybrid web request/thread lifestyles it seems I do not fully understand the technical requirements and have been doing something I don't actually need to do. With this code interface IUnitOfWork { } interface IWebUnitOfWork : IUnitOfWork { } interface IThreadUnitOfWork : IUnitOfWork { } class UnitOfWork : IWebUnitOfWork, IThreadUnitOfWork { } container.RegisterPerWebRequest<IWebUnitOfWork, UnitOfWork>(); container

When would you need SimpleInjector hybrid registration? (How can an object hosted in IIS be called without a HttpContext?)

折月煮酒 提交于 2020-01-16 02:05:08
问题 Following on from my recent question regarding SimpleInjector and hybrid web request/thread lifestyles it seems I do not fully understand the technical requirements and have been doing something I don't actually need to do. With this code interface IUnitOfWork { } interface IWebUnitOfWork : IUnitOfWork { } interface IThreadUnitOfWork : IUnitOfWork { } class UnitOfWork : IWebUnitOfWork, IThreadUnitOfWork { } container.RegisterPerWebRequest<IWebUnitOfWork, UnitOfWork>(); container

How To Scope Individual Libraries Using Auto Registration

一个人想着一个人 提交于 2020-01-16 00:45:00
问题 Is it possible to set/change the dependency lifetime scoping options (Transient, Single, PerWebReqest, etc...) for one, two or x number of specific assemblies if you're auto registering/discovering your dependencies? I have sample code below: public class RegistrationPackage : IPackage { public void RegisterServices(Container container) { var @namespace = "ConsoleLib"; var assemblies = AppDomain.CurrentDomain.GetAssemblies() .Where(a => a.FullName.StartsWith(@namespace)) .Select(a => a)

SessionPerWebRequest UoW SimpleInjector ActionFilterAttribute

天涯浪子 提交于 2020-01-15 19:11:10
问题 I am using SimpleInjector and want to create a UnitOfWork Per WebRequest Using an UnitOfWorkFactory . I want to do this by using an ActionLiterAttribute so that every web request will begin a new UnitOfWork The only problem that I have is to pass the IUnitOfWorkFactory to the ActionFilterAttribute class. There is a similar question about this online but there is a solution given using Ninject , Unfortunately with SimpleInjection there is no equivalent to Bind a filter. This is what I have

Simple Injector with dependency on two objects that implement same interface

醉酒当歌 提交于 2020-01-14 14:22:45
问题 I'm writing an application (exposed via an ASP.NET web API) that's entire purpose is to consume two data sources, and expose the similarities and differences. So the API has the following setup: public class FooController : WebAPI { public FooController(IFooRepository repoFromSourceA, IFooRepository repoFromSourceB) { ... } } Maintaining the distinction of which one is of which source (SourceA and SourceB cannot be interchanged) seems to make container.RegisterCollection(..) impossible (or

Simple Injector with dependency on two objects that implement same interface

只愿长相守 提交于 2020-01-14 14:22:07
问题 I'm writing an application (exposed via an ASP.NET web API) that's entire purpose is to consume two data sources, and expose the similarities and differences. So the API has the following setup: public class FooController : WebAPI { public FooController(IFooRepository repoFromSourceA, IFooRepository repoFromSourceB) { ... } } Maintaining the distinction of which one is of which source (SourceA and SourceB cannot be interchanged) seems to make container.RegisterCollection(..) impossible (or

Winforms - MVP Pattern: Using static ApplicationController to coordinate application?

廉价感情. 提交于 2020-01-11 03:09:28
问题 Background I'm building a two-tiered C# .net application: Tier 1: Winforms client application using the MVP (Model-View-Presenter) design pattern. Tier 2: WebAPI RESTful service sitting on top of Entity Framework and SQL Server. Currently, I have questions relating to the overall architecture of the Winforms client application. I'm new to programming (about a year) but I've made good progress with this application. I want to step back and re-evaluate my current approach to check that I'm

Replace Ninject with Simple Injector

假装没事ソ 提交于 2020-01-10 11:33:47
问题 I've used Ninject for my application. Ninject is really simple and easy to learn, but its quite slow and I try to use another IoC to compare if its faster as with Ninject. There are a lot of IoC containers for MVC3 and Simple Injector looks really good to me, but I've a lot of problems with replacting Ninject with Simple Injector. Especially with the AutoMapper . I try to convert this lines into Simple Injector code. Bind<ITypeMapFactory>().To<TypeMapFactory>(); foreach (var mapper in

Constructor injection with Quartz.NET 3.0.3 and Simple Injector How To

假如想象 提交于 2020-01-04 02:11:07
问题 I am trying to use Quartz.Net v3.0.3 and Simple Injector in a windows service. I have a job class below which i would like to inject some dependencies such as my logger into. public class JobWorker : IJob { private ILogger _logger; public JobWorker(ILogger logger) { _logger = logger; } public Task Execute(IJobExecutionContext context) { return Task.Run(() =>_logger.Log("Do Work")); } } I tried registering Container.Register<IJob, JobWorker>(); on my DI layer but this doesn't help. If i remove