inversion-of-control

Transient Lifestyle requires HttpContext?

北战南征 提交于 2019-12-25 09:16:57
问题 I am registering my component like this: public static void Register(IWindsorContainer container) { container.Register(Classes.FromAssembly(Assembly.GetAssembly(typeof(GenericBaseRepository))) .InSameNamespaceAs<GenericBaseRepository>() .WithService.DefaultInterfaces() .LifestyleTransient()); } I am then resolving it in a piece of code that has no HttpContext: var baseRepository = ContainerManager.Container.Resolve<IBaseRepository>(); (IBaseRepository being an interface implemented by

using IoC container in azure functions

℡╲_俬逩灬. 提交于 2019-12-25 04:12:10
问题 I have been used to writing Windows Services using TopShelf to do all stuff which cannot be done in a web request and am slowly moving to using azure functions. With topshelf I could generally do scan and register on start of a service use nested container for each ticket / request How can I use IOC in an azure function call ? Should I be using it at all ? 回答1: No there isn't currently a way to do IOC in a natural way in Azure Functions. Generally you'd want to initialize your IOC container

Ioc/DI - Why do I have to reference all layers/assemblies in application's entry point?

安稳与你 提交于 2019-12-25 04:09:18
问题 (Related to this question, EF4: Why does proxy creation have to be enabled when lazy loading is enabled?). I'm new to DI, so bear with me. I understand that the container is in charge of instantiating all of my registered types but in order to do so it requires a reference to all of the DLLs in my solution and their references. If I weren't using a DI container, I wouldn't have to reference the EntityFramework library in my MVC3 app, only my business layer, which would reference my DAL/Repo

Ninject in a three tier application

风格不统一 提交于 2019-12-25 02:57:49
问题 I am building a standard three tier app. 1 Console app for front end 2 Business logic layer 3 Data layer The main purpose is to display some customer data from a database table. I'm trying to follow the guide lines in the book "Dependency Injection in .NET" by having no reference from the console to the data layer, and none from the business layer to the data layer. Allowing for easy swapping of the front end and the data layers if needed. Let's say I have a service at the business layer

is SFig language syntax efficient and clear (and better than Spring-Framework's XML DSL)?

主宰稳场 提交于 2019-12-25 01:19:09
问题 ADDENDUM EDIT: Have not accepted an answer to this as there has not been any feedback from experienced Spring Framework developers. I've been working on a replacement DSL to use for Spring-Framework applicationContext.xml files (where bean initialization and dependency relationships are described for loading up into the Spring bean factory). My motivation is that I just flat out don't like Spring's use of XML for this purpose nor do I really like any of the alternatives that have been devised

Can someone explain the magic going on in Prism's resolve<> method?

て烟熏妆下的殇ゞ 提交于 2019-12-24 23:15:09
问题 I've got a CustomersModule.cs with the following Initialize() method: public void Initialize() { container.RegisterType<ICustomersRepository, CustomersRepository>(new ContainerControlledLifetimeManager()); CustomersPresenter customersPresenter = this.container.Resolve<CustomersPresenter>(); } The class I resolve from the container looks like this: class CustomersPresenter { private CustomersView view; private ICustomersRepository customersRespository; public CustomersPresenter(CustomersView

Autofac - How to register a class<,> to interface<>

这一生的挚爱 提交于 2019-12-24 21:28:46
问题 I'm trying to register my repository class which is take two generic parameter to repository interface (one parameter generic). public class RepositoryBase<T, O> : IDataAccess<T> public interface IDataAccess<T> 回答1: Autofac don't know how to set the second generic parameter of RepositoryBase when you only want to provide one generic argument in the interface. So you need to somehow specify the second argument in order to instantiate the service unless you are happy with object , dynamic or

Construct a System.Type for a generic interface with known type of T [duplicate]

做~自己de王妃 提交于 2019-12-24 20:56:40
问题 This question already has answers here : C# use System.Type as Generic parameter (2 answers) Closed last year . PROBLEM DESCRIPTION I have an interface definition IFoo<TBar> : IFoo and a method CreateFooUsingBarType(Type barType) . I need the method to resolve an IFoo<TBar> using a dependency injection tool given a specified System.Type instance that defines TBar . Don't ask how I ended up here. I am stuck within these boundaries. EXAMPLE public IFoo CreateFooUsingBarType(Type barType) { var

.NET Core DI, register a default implementation for a package

岁酱吖の 提交于 2019-12-24 17:44:09
问题 How can one register a default implementation using the IoC container for .NET Core and also provide a way to override the existing implementation ? For example, I might want to create a package which provide a default implementation for some service. namesapce Package { public interface ISomeService { } public class Default : ISomeService { } } This service is then used inside the same package. namesapce Package { public class Service { Service(ISomeService service) { } } } How to register

Symfony - Wrapper/Helper classes having access to entity's repository

半城伤御伤魂 提交于 2019-12-24 16:16:02
问题 Alright so I'm converting a small laravel project to symfony (will get bigger, and the bundling architecture symfony uses will be ideal) I'm apparently spoiled with laravels facades and eloquent working with existing databases almost right out of the box. I can't find the most appropriate way to have a wrapper or "helper" class get access to an entities repository. first let me give a few examples then I will explain what I have attempted. (I'm willing to bounty some points for a good answer