dependency-injection

Spring properties (property-placeholder) autowiring

£可爱£侵袭症+ 提交于 2019-12-18 13:53:12
问题 I have in my applicationContext.xml <context:property-placeholder location="classpath*:*.properties" /> <bean id="clientPreferencesManager" class="pl.bildpresse.bildchat2.business.ClientPreferencesManager" > <property name="clientApiUrl" value="${clientapi.url}" /> </bean> Is it possible to do the same by autowire ? Something like : @Autowired @Qualifier("${clientapi.url}") public void setClientApiUrl(String clientApiUrl) { this.clientApiUrl = clientApiUrl; } 回答1: You can use @Value : @Value(

Simple Injector: how to inject HttpContext?

谁说胖子不能爱 提交于 2019-12-18 13:20:11
问题 I have started using Simple Injector as my DI container (mostly for performance reason: if somebody has suggestions, please let me know) but some of the classes I wrote use HttpContextBase as constructor parameter. I have resolved for now removing it from the constructor and creating a Property, something like this: public HttpContextBase HttpContext { get { if (null == _httpContext) _httpContext = new HttpContextWrapper(System.Web.HttpContext.Current); return _httpContext; } set {

Modify bundle configuration from another bundle

家住魔仙堡 提交于 2019-12-18 13:20:04
问题 I was wondering whether there's a possible to modify a bundles configuration from another bundle. Let's say, for example, I'm using the FOSUserBundle with the following configuration: fos_user: db_driver: orm firewall_name: main user_class: Acme\UserBundle\Entity\User And now, I want to change the user class when loading a specific extension (the AcmeFoobarExtension ). Is it possible to change the configuration when loading the AcmeFoobarExtension ? For example: <?php namespace Acme

ASP.NET MVC + fluent nNibernate, what IoC tool?

三世轮回 提交于 2019-12-18 13:17:43
问题 I'm working on a ASP.NET MVC project where we have decided to use Fluent nHibernate for dataccess. To enable loose coupling we go for a IoC/DI pattern. My questions is what IoC tool to go for. I've tried to find the differences between windsor, ninject, spring, structuremap and unity, but it's difficult to see the benefits each one has to offer. Whats your experience? 回答1: I use StructureMap and it's very easy to use. Personally I don't like to configure using xml and StructureMap makes it a

Named Instances and a Default Instance in StructureMap?

老子叫甜甜 提交于 2019-12-18 13:16:05
问题 In my StructureMap bootstrapping code I'm using a custom convention to scan assemblies and add interface/implementation pairs to the object graph as named instances. Essentially I have some logic which checks configuration settings and drills down to this statement depending on various conditions: registry.For(interfaceType).Use(type) .Named(implementationName); This adds all of the named instances well enough. However, I'd also like to add a default instance in the event that an instance

How to include/inject functions which use $scope into a controller in angularjs?

陌路散爱 提交于 2019-12-18 13:11:31
问题 I am trying to include a library of functions, held in a factory, into a controller. Similar to questions like this: Creating common controller functions My main controller looks like this: recipeApp.controller('recipeController', function ($scope, groceryInterface, ...){ $scope.groceryList = []; // ...etc... /* trying to retrieve the functions here */ $scope.groceryFunc = groceryInterface; // would call ng-click="groceryFunc.addToList()" in main view /* Also tried this: $scope.addToList =

Fork a child process and inject dependency

懵懂的女人 提交于 2019-12-18 13:10:00
问题 I currently have an operation in a module that is blocking, so I'm looking at making this into a child process that I fork instead. If I want to do that, then I of course need to modify the architecture of my module. The module requires that a dependency is injected by calling the module as a function, passing in the dependency, like so: var dependency = { name: "Bob" } require('worker')(dependency) Then in my worker module: module.exports = function (dependency) { // Outputs { name: "Bob" }

Service Locator, Dependency Injection (and Container) and Inversion of Control

主宰稳场 提交于 2019-12-18 13:01:39
问题 I've been programming for some time but never got interested in knowing in theory what each concept means, I may be using a variety of programming concepts, but without knowing it. Service Locator : For me, refers to a record of shortcuts to speed up development by reducing the amount of code. One question is: may Locator refer to namespaces/classes only, or I can have a registry of variables? Here is my understanding of it: $locator = new ServiceLocator() $locator->set('app', new System

How to avoid having injector.createInstance() all over the place when using guice?

此生再无相见时 提交于 2019-12-18 13:01:24
问题 There's something I just don't get about guice: According to what I've read so far, I'm supposed to use the Injector only in my bootstrapping class (in a standalone application this would typically be in the main() method), like in the example below (taken from the guice documentation): public static void main(String[] args) { /* * Guice.createInjector() takes your Modules, and returns a new Injector * instance. Most applications will call this method exactly once, in their * main() method. *

Is mixing constructor-based and setter-based injections a bad thing?

混江龙づ霸主 提交于 2019-12-18 13:01:18
问题 I have a class for products import from CSV file operation which requires about 7 parameters. This is an info which is definitely needed for importer. All of this parameters have the same life time. In the end we must have an Immutable Object. I was too scared to list all of them in constructor because of its affect to readability and decided to move 3 of them to setters injection. But obviously it's not an elegant solution. Questions: 1) Is mixing constructor-based and setter-based