inversion-of-control

Two beans with the same name results in ConflictingBeanDefinitionException despite using @Primary

你离开我真会死。 提交于 2019-12-07 12:19:09
问题 I have an application initializer class that is used to insert application specific data to database. @Component("applicationInitializer") public class ApplicationInitializer { @PostConstruct public void init(){ // some clever code here } } There is also DevApplicationInitializer class that is used to initialize database with some sample data on developer machine (this class is excluded when deploying production code). @Component("applicationInitializer") @Primary public class

How can I spring.net inject in to methods?

不羁的心 提交于 2019-12-07 10:22:16
问题 I posted to following on the spring.net forum but also hoped I may get some value views here: I am looking at some advice as to how I might achieve the following requirement. Firstly some background - I am using Spring.NET to achieve IOC depdenecny injection in to my asp.net c# multi tier web application. Injection is achieved via spring.net xml configuration file with all my development achieved by developing against interfaces and injecting in an interface implemented class where required.

Platform-specific IoC in MVVMCross

◇◆丶佛笑我妖孽 提交于 2019-12-07 09:53:18
问题 I'm giving a MVVMCross a spin, to see if it will be of use in some bigger projects coming up, and it's great. I like the navigation, viewModel location and general cross-platform approach, which is just what I need. However, I'm a bit stuck on splitting out some of the dependency injection depending on the platform. So, we have the basic application, with a shared portable library, that initialises the service references when starting up: public TwitterSearchApp() { InitaliseServices(); }

Actionfilter Injection in ASP.NET MVC 5

落爺英雄遲暮 提交于 2019-12-07 09:00:59
问题 I have a simple filter. public class IsAdmin : ActionFilterAttribute, IAuthenticationFilter { private string _roleName; IBusinessIdentity _identity; public IsAdmin(string roleName, IBusinessIdentity identity) { this._roleName = roleName; this._identity = identity; } public void OnAuthentication(AuthenticationContext filterContext) { } public void OnAuthenticationChallenge(AuthenticationChallengeContext filterContext) { if (!_identity.Roles.Contains(_roleName)) filterContext.Result = new

How to configure Unity to inject an array for IEnumerable

旧街凉风 提交于 2019-12-07 08:32:42
问题 I have a class which takes an IEnumerable constructor parameter which I want to resolve with Unity and inject an array of objects. These simple classes illustrate the problem. public interface IThing { int Value { get; } } public class SimpleThing : IThing { public SimpleThing() { this.Value = 1; } public int Value { get; private set; } } public class CompositeThing : IThing { public CompositeThing(IEnumerable<IThing> otherThings) { this.Value = otherThings.Count(); } public int Value { get;

Castle Windsor: Best way to log when a component is registered?

霸气de小男生 提交于 2019-12-07 06:51:55
问题 I would like to log when a component (interface and implementation) is registered to my container. What is the best way of doing this? I found the IKernelEvents interface that looks promising but I can't find how to actually use it. 回答1: Nevermind, found that IKernel implements IKernelEvents Therefore simply WindsorContainer.Kernel.ComponentRegistered += (k, h) => _logger.Debug("Registered {0} - {1}/{2}", k, h.ComponentModel.Service.FullName, h.ComponentModel.Implementation.FullName); 来源:

Property Dependency Injection used in Constructor using Unity

落爺英雄遲暮 提交于 2019-12-07 06:33:23
问题 Ok, I have a dependent property defined in a base class and I'm trying to use it inside of the constructor of its derived class but that does not work, the property appears as null. Unity resolves the dependent property AFTER resolving an instance with container.Resolve(); One alternative I have is to add a IUnityContainer parameter to my MyViewModel class constructor and set the ILogger property my self with something like: public MyViewModel(IUnityContainer container) { Logger = container

How should I order my ctor parameters for DI/IOC?

十年热恋 提交于 2019-12-07 05:50:42
问题 I'm a bit of a DI newbie, so forgive me if this is the wrong approach or a silly question. Let's say I have a form which creates/updates an order, and I know it's going to need to retrieve a list of products and customers to display. I want to pass in the Order object that it's editing, but I also want to inject the ProductsService and CustomersService as dependencies. So I will want my IoC container (whichever one I go with) to supply the services, but it'll be up to the calling code to

Define an initialization order of WebActivator.PreApplicationStartMethod classes

主宰稳场 提交于 2019-12-07 05:47:41
问题 I have several WebActivator.PreApplicationStartMethod decorated classes. One is for Ninject, another class for AwesomeMVC and a third one is for background task scheduler. The problem is that the scheduler class needs to take advantage of the dependecies, that are resolved by IoC container. My questions are: Can I have several WebActivator.PreApplicationStartMethod classes? Can I define order, in which they are initialized, so that IoC, being the most important, comes first? Can WebActivator

What should be constructed through an IOC container?

前提是你 提交于 2019-12-07 03:52:22
问题 How do you determine which classes should be constructed through an IOC container, and which ones shouldn't. I've worked on projects with both extremes and it seems like interfaces should only be used when the classs specifies a specific technoliogy like logging or data access? Where do people draw the line between the two? 回答1: I don't draw any line - the more, the merrier. What happens is that the more you can manage to split up your API in small units, the closer you get to the Single