FAQ Database Discussion Community


Are dependencies shared?

angularjs,dependency-injection
Let's say I have 3 modules: angular.module('A', []) angular.module('B', ['A']) angular.module('C', ['B', 'A']) In terms of dependency injection, will B and C share the same instance of module A, or will separate instances be injected into each of them?...

How to override default escape function of blade in laravel 5?

php,dependency-injection,laravel-5
I almost solved my problem in this question. Now I must find a way to override the default blade escape function. I think there's a way to create a class that extends and override the behavior of BladeCompiler class, this way I could make something like this: class MyCustomCompiler extends...

Property injection with Simple Injector 1 in Unity3D under .NET 3.5

c#,unity3d,dependency-injection,.net-3.5,simple-injector
I'm trying to use Simple Injector v1.6 in combination with the Unity3D game engine (v5.0). I need to use Property Injection because Unity3D has control over the assembly and will not allow Constructor Injection, because (how unfortunate it may be) that's just the way Unity3D's API is currently. Unity3D targets...

Is there a way to use AutoFac Web Api Authorization Filters through Attributes instead of injection?

asp.net-web-api,filter,dependency-injection,authorization,autofac
I have an Autofac Web Api Authorization Filter like that: public class MyAuthorizationFilter : IAutofacAuthorizationFilter { public void OnAuthorization(HttpActionContext actionContext){} } public class MyAuthorizationAttribute : Attribute { public MyAuthorizationAttribute() { } } Right now the only way I can have an Autofac Web Api Authorization Filter is through injecting it...

Define bean using factory method in plain Java EE - WITHOUT Spring

java,java-ee,dependency-injection,autowired,inject
I want to create a bean which can be automatically injected (autowired) by plain Java EE, not with Spring. The code I have is this: import javax.ws.rs.client.Client; import javax.ws.rs.client.ClientBuilder; @ApplicationScoped public class MyConnector { .... private Client client = ClientBuilder.newClient(); .... } I'd like to use dependency injection like that...

Instantiate EJB Via Factory

java,dependency-injection,ejb,java-ee-7
So I have a service I am hooking by instantiating it through a factory that creates a proxy so it can process some annotations I have on the service. So my question is this...is there a way with JavaEE to have my dependency injection instantiate the instances of said service...

Inject factory and let it perform creation, or inject everything?

c#,dependency-injection
Is it good practice to inject a factory, then perform instantiation of many objects inside a constructor? private readonly SafeClient<AccountProxy, IAccountService> _accountProxy; private readonly SafeClient<AccountClassProxy, IAccountClassService> _accountClassProxy; private readonly SafeClient<CarrierProxy, ICarrierService> _carrierProxy; private readonly SafeClient<TransportationTypeProxy, ITransportationTypeService> _transportationTypeProxy; public AccountController(ISafeClientFactory clientFactory) {...

Symfony2 get public services in controller

service,dependency-injection
Much ink has flowed about Sf2 controller/container. I face with follow situation: app/console container:debug security ... > 4 [container] Information for service security.token_storage Service Id security.token_interface Class Symfony\Component\Security\Core\Authentication\Token ... ... Public yes LoginBundle\DefaultController.php use Symfony\Bundle\FrameworkBundle\Controller\Controller; class DefaultController extends Controller { public function indexAction() { dump(Controller::get('security.token_storage')); ... works OK, obviously....

Dependency Injection for concrete .Net classes

c#,.net,dependency-injection,ninject
What is the preferred way for injecting/isolating classes that are sealed in dlls and do not implement interfaces? We use Ninject. Let's say that we have a class "Server" and we want to inject/isolate the class TcpServer which "Server" uses. Don't want to be too specific because I want to...

Is it possible to construct an object partially with Spring DI and partially with Jersey DI?

spring,dependency-injection,jersey,jersey-2.0,hk2
I have a class JerseyWebService which uses Jersey DI to inject dependency @Path("/baskets") public class JerseyWebService { @Inject ExternalApiServiceInterface api; ... } The dependency is specified in the binder public class CustomBinder extends AbstractBinder { @Override protected void configure() { bind(ExternalApiService.class).to(ExternalApiServiceInterface.class); ... } But the problem here is that ExternalApiService...

What is the proper way to setup integration tests in grails 2.5 using junit?

grails,junit,dependency-injection,integration-testing
With grails 2.2 the following code (which is an integration test for a GORM class) was working fine: public class DbDeploymentIntegrationTests extends GroovyTestCase { DeploymentStorageImpl deploymentStorage DeploymentService deploymentService @Override protected void setUp() { super.setUp() deploymentStorage = deploymentService.deploymentService.deploymentStorage } ... } When I updated to grails 2.5, this is now failing:...

symfony container: injected class's constructor not called

php,symfony2,dependency-injection,constructor-injection
When I inject a service into another via constructor injection, the constructor of the injected class is not being called. Has anyone an explanation for this. What am I overlooking? I created this little sample for demonstration purposes: services.yml services: foo.A: class: Acme\FooBundle\A foo.B: class: Acme\FooBundle\B arguments: a: "@foo.A" Class...

Symfony2 : Does Dependency Injection List size have an impact on performances ?

symfony2,dependency-injection,concept
I am simply wondering if the size of the dependency injection list size might become a problem or decrease performances. A simple case is : Is it better to have a X services or a factory that can make X new $class ? Thanks. ...

Unable to inject with unity a complex type to web api 2

c#,asp.net-web-api,dependency-injection,unity,asp.net-web-api2
I have a complex type to inject into a webapi controller and I am unable to resolve this dependency public class MyController(IMyComplexType) The implementation of IMyComplexType has at least 5 dependencies I1, ... I5(so its implementation recieve I1...I5) I have a Bootstrapper class to Register all dependencies, below a snippet...

Breaking cyclic dependency in constructor

java,dependency-injection,dependencies,circular-dependency,decoupling
I'm writing a Java class to manage a hex map (class GameMapImpl implements GameMap) that contains Cell objects. Cell objects are saved in a HashMap<Hex,Cell>, where the key is the position on the hex map. The whole thing used to be very tightly coupled between cells and GameMap, with a...

Angular 2 di container

javascript,dependency-injection,typescript,angular2
I m actually studying Angular 2 and I was wondering how does the team do to handle dependency injection in their component ? Explanation It seems that Ng2 is based on ES7 decorator through TypeScript. In fact, class decorator is "launch" (I mean, the code of the decorator) is only...

How does @Inject in Scala work

scala,playframework,dependency-injection,playframework-2.0
I'm wondering how does @Inject annotation in Play-Scala works. It obviously injects a dependency, but I'm curious how is it working. When I was using it on class extending controller and set routes generator to injectroutesgenerator it seems to autmagically create objects from those classes, but how do I use...

Autofac - How to get class name while creating instance

c#,dependency-injection,inversion-of-control,autofac,ioc-container
I have question about Autofac : How can I get name of class which request instance from container? Is it possible to get name of the class "Autofac_Test" passed into constructor by autofac when object is created? My code: using System; using System.Diagnostics; using System.Reflection; using Autofac; using Xunit; public...

What is a good pattern for using multiple strategies one after another that is also extensible

c#,dependency-injection,unity,ioc-container,factory
I have a class that needs to get some data to perform analysis. Let's say the interface for getting the data is as follows: public interface IDataFetcher { List<someobject> GetData(); } In a very simple case my class will use this interface as follows in one of its methods: void...

AngularJS: Access a factory or service from 3rd party library

javascript,angularjs,web-applications,dependency-injection
Here is my problem: I am building an application mostly angular-based, but also using some non-angular code. I have organized my code in modules, including some factories. In particular I have a factory dedicated to logging, which is injected in various modules. What if I want to access this logging...

Resolving components when using container.RegisterAll()

c#,dependency-injection,simple-injector
I'm having a problem when trying to inject dependencies in my classes. I'm just trying it around to learn more about simple injection and DI when I got stuck here. So this is my Main method: static void Main(string[] args) { var container = new Container(); // Registrations here container.RegisterAll<ISimpleLogger>(typeof(DebugLogger),...

Android Dagger 2 POJO field Inject null

android,dependency-injection,dagger-2
Just started using Dagger 2 today and I'm a bit confused on how exactly I need to set everything up. I'm trying to inject a POJO, but it's always null. First, some code: App.java private AppComponent appComponent; @Override public void onCreate() { super.onCreate(); appComponent = DaggerAppComponent .builder() .appModule(new AppModule(this)) .build();...

Why does Unity RegisterType not re-register mappings correctly

.net,dependency-injection,unity
I need to register many Type mappings but for just a few I need to re-register using different dependecy injected Properties. With Unity this appears impossible and it seems to be a bug with RegisterType<TFrom, TTo>() Here is a unit test to demonstrate that the 2nd call does not clear...

Retrofit unit tests to large solution, IOC, Moq

c#,vb.net,unit-testing,dependency-injection,inversion-of-control
I am in the process of retrofitting unit tests for a asp.net solution written in VB.Net and c#. The unit tests need to verify the current functionality and act as a check for future breaking changes. The solution comprises of: 1 MVC web project written in vb.net (don't ask, it's...

'StructureMap.ObjectFactory' is obsolete

c#,dependency-injection,structuremap
I implemented a interface injection using StructureMap as describe below. Code ObjectFactory.Initialize(x => { x.For<IRepository>().Use<SQLRepository>(); }); But it is giving a warning as follows Warning Warning 2 'StructureMap.ObjectFactory' is obsolete: 'ObjectFactory will be removed in a future 4.0 release of StructureMap. Favor the usage of the Container class for future...

How do I get PicoContainer to start/stop/dispose a component injected by a factory?

java,dependency-injection,factory,picocontainer
I have a PicoContainer which caches all components. Since it caches all components, I expect it to call start, stop and dispose at the appropriate points in the container lifecycle. However, I'm finding that if I construct a component using a FactoryInjector, these methods don't get called at all, despite...

How do I intercept Castle Windsor's component resolution to override dependencies?

c#,dependency-injection,inversion-of-control,castle-windsor
I'm looking for a way to hook into Castle Windsor's resolution process so that I can do something like: if (componentCanBeResolvedElsewhere) { return elsewhere.Resolve<TService>(); } else { windsorContainer.Resolve<TService>(); } I want Castle Windsor to handle the majority of my dependencies, but I want to provide an ability to 'fill-in the...

How to test use of DI (NInject)

.net,testing,dependency-injection,ninject
I have an ASP.NET MVC app that has a NInject container for dependency injection. As advertised, IoC makes it pretty easy for me to test components in isolation, and then easy to compose components in the application. I want to test my use of the DI. I don't want to...

Injected dependencies not accessible in class methods for AngularJS

javascript,angularjs,dependency-injection,ecmascript-6
I'm using ES6 classes for Angular controllers and I'm running into a slight annoyance with dependency injection. Take this controller, for example (obviously not a real class). class PersonController { constructor(MyDependency) { MyDependency.test(); // this works } sendEvent() { MyDependency.test(); // MyDependency is undefined } } PersonController.$inject = ['MyDependency']; export...

What's the equivalent of CastleWindsor's container.Release in LightInject?

asp.net-web-api,dependency-injection,castle-windsor,light-inject
I saw ASP.NET Web API dependency injection in Seemann's site. It uses CastleWindsor though. request.RegisterForDispose( new Release( () => this.container.Release(controller))); What's the equivalent of CastleWindsor's container.Release in LightInject? http://blog.ploeh.dk/2012/10/03/DependencyInjectioninASP.NETWebAPIwithCastleWindsor/...

Is there a strong case against making my TyphoonAssembly a singleton? If so, why? If not, is there a recommended way to do so?

ios,objective-c,dependency-injection,typhoon
I'm getting started with Typhoon and finding that it is annoying to keep writing constructors with additional assembly arguments. So it is tempting to just make my TyphoonAssembly a singleton. But I've yet to see that done in any examples, and I do see examples where constructor or property injection...

How to specify constructor when registrating class in asp.net 5 with default Dependecy Injection

dependency-injection,asp.net-5
Is there are possibility to instantiate class using ASP.NET 5 default Dependency Injection when that class have constructor with parameters? I would like to register Repository with constructor that accepts connection_string. UPDATE I think that I can rephrase the question. I would like to specify which constructor will be called...

Injecting an instance using Unity whose constructor parameter is not known

design-patterns,dependency-injection,unity,constructor-injection
I have an interface as follows public interface IDataProvider { List<string> GetData(); } Implementation of it public class TextDataProvider: IDataProvider { public TexDataProvider(string source){...} public List<string> GetData() {...} } One of my services uses IDataProvider to get data. Different implementations could be injected by changing the Unity Register method with...

Globaly Shared Substitution with Dice Dependency Injection

php,dependency-injection
I'm trying to get familiar with Dice Dependency Injection but I'm failing with my first trials. I want to tell Dice that each class depending on MyInterface should get an instance of MyInterfaceImpl so I'm evaluating this with MyClass. Obviously I'm missing some detail with the rules in Dice. This...

Dependency injection using Azure WebJobs SDK?

c#,azure,dependency-injection,azure-webjobs
The problem is that the Azure WebJobs SDK supports only public static methods as job entry-points which means there is no way of implementing constructor/property injection. I am unable to find anything about this topic in official WebJobs SDK documentation/resources. The only solution that I came across is based on...

container doesnt work using inside of a simple controller class in Symfony 2

php,symfony2,dependency-injection
My Error: > ContextErrorException: Catchable Fatal Error: Argument 1 passed to > Agc\ManagerBundle\Lib\grafica::__construct() must implement interface > Symfony\Component\DependencyInjection\ContainerInterface, none given, > called in > C:\wamp\www\galileo\src\Agc\BackendBundle\Controller\DefaultController.php > on line 20 and defined in > C:\wamp\www\galileo\src\Agc\ManagerBundle\Lib\grafica.php line 10 My class grafica: use Symfony\Component\DependencyInjection\ContainerInterface; /** *...

Receiving a NoClassDefFoundError even though jar is successfully downloaded via Maven and referenced in pom.xml

xml,eclipse,spring,maven,dependency-injection
Runtime exception I am receiving is: Caused by: java.lang.NoClassDefFoundError: org/springframework/core/io/Resource Even though there are no errors within my project and I've updated via 'Maven update' and running 'Maven clean install' builds successfully. The dependency in my pom.xml is: <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>4.1.4.RELEASE</version> <scope>compile</scope> </dependency> Have also tried with scope set...

Simple Injector Dependency Resolution Error

c#,.net,asp.net-web-api,dependency-injection,simple-injector
I am following onion architecture and using simple injector in the DependencyResolution Project. Here is my architecture: 1-Core - Domain Classes - Repository Interfaces - Service Interfaces 2-Infrastructure - Data - Dependency Resolution - Repository Interfaces Implementation - Service Interfaces Implementation 3-WebApi - Web Api Project 4-WebClient - My AngularJs...

How to Inject a context from a test

dependency-injection,eclipse-rcp,integration-testing,e4
I'm testing an (Eclipse 4) application (I'm not talking about unit test but more integration and system-test). I've a recurrent problem I need to solve. I have to "inject" (@Inject) a context from the test into the class(es) under test. In other words I need the test does what the...

How to use Autofac to inject specific implementation in constructor

c#,asp.net-mvc,dependency-injection,autofac
I have two classes that take a ILastActivityUpdator as a constructor parameter: UserService and AnonymousUserService. public AnonymousUserService(ILastActivityUpdator lastActivityUpdator) { if (lastActivityUpdator == null) { throw new ArgumentNullException("lastActivityUpdator"); } this.lastActivityUpdator = lastActivityUpdator; } And similar as above for UserService: public UserService(ILastActivityUpdator lastActivityUpdator) { if (lastActivityUpdator == null) { throw new ArgumentNullException("lastActivityUpdator");...

How to inject a Map using the @Value Spring Annotation?

java,spring,dependency-injection,annotations,spring-annotations
How can i inject values into a Map from the properties file using the @Value annotation in Spring ? My Spring Java class is and i tried using the $ but, got the following error message Could not autowire field: private java.util.Map Test.standard; nested exception is java.lang.IllegalArgumentException: Could not resolve...

cleanest way to create multiple beans of the same class with different properties

java,spring,dependency-injection,spring-bean,spring-properties
Say I have this properties file: students.bill.firstname=John students.bill.lastname=Doe students.bill.age=20 students.jim.firstname=Jim students.jim.lastname=Wright students.jim.age=21 . . . I want an xml bean that contains a map of students that has their firstname as the key. Object example: Student.java public class Student { String firstname; String lastname; Integer age; } Classroom.java public class...

How to have SimpleInjector resolve viewmodel dependencies?

asp.net-mvc,asp.net-web-api,dependency-injection,simple-injector
I'm trying to use SimpleInjector 2.7.3 (IoC container) within an Asp.Net MVC + Web API application. I've had a couple of problems trying to set it up for both MVC and Web API on the same project until I found this link: http://methoddev.com/blg/let-s-talk-software/310/simple-injector-in-asp-net-mvc-webapi After following the link's example, here's what...

Symfony2: Dependency injection reliant on request

php,symfony2,dependency-injection,proxy-classes
Preamble My Symfony2 application will be accessed from several TLD's. Depending on the TLD I want to use a different swiftmailer mailer. I however failed to dynamically inject the correct mailer despite trying a multitude of approaches (service factory, compiler pass, DI extension, "dynamic alias"). This lead to a fundamental...

Property injection with Unity

c#-4.0,dependency-injection,unity
i encoutered problem with unity, i want to use property injection, here is what i had in my code : config of the container : public static void RegisterTypes(IUnityContainer container) { container.RegisterType<GTModelContainer, GTModelContainer>(new HttpContextLifetimeManager<GTModelContainer>()) .RegisterType<IUnitOfWork, UnitOfWorkGT>() .RegisterType<ILogger, Logger>(new ContainerControlledLifetimeManager()) .RegisterType<ISocieteServices, SocieteServices>() ; } SocieteService Class : public class...

How to access nested Unity Dependency Injection created objects?

c#,asp.net-mvc,dependency-injection,unity
This is a beginner question for Unity so forgive me. In my Unity Config I have the following that creates my database context (Entity Framework), Unit of Work, and a Repository pattern object (from reverse pocos and generic repo/uow): container .RegisterType<IDataContextAsync, myDbContext>( new PerRequestLifetimeManager(), new InjectionConstructor(new object[] { connString }))...

Simple Injector Identity UserManager Registration Error

c#,asp.net,dependency-injection,asp.net-identity,simple-injector
I am following Onion Architecture and using Identity Framework. In my Core project, I have: public interface IUserRepository : IDisposable { // Repository methods....... } In my Architecture.Repository, I have public class UserRepository : IUserRepository { // This is Identity UserManager private readonly UserManager<AppUser, int> _userManager; private readonly IAuthenticationManager _authenticationManager;...

avoiding container strings in dependency injection in symfony

php,symfony2,dependency-injection
New to symfony and php. I was able to successfully define a service and inject the doctrine entity manager into it. It works fine but during the initialization I have to pass a string that contains the service name as follows: $eRep = $this->container->get('employee_repository'); Can this be avoided? Can this...

Multiple dex files define Ljavax/inject/Inject using TMDb dependencies

java,android,dependency-injection,gradle
I'm new to gradle and android dev, when I add the dependencies needed for the themovieDB API I get errors when I compile :app:dexDebug AGPBI: {"kind":"SIMPLE","text":"UNEXPECTED TOP-LEVEL EXCEPTION:","position":{},"original":"UNEXPECTED TOP-LEVEL EXCEPTION:"} AGPBI: {"kind":"SIMPLE","text":"com.android.dex.DexException: Multiple dex files define Ljavax/inject/Inject;","position":{},"original":"com.android.dex.DexException: Multiple dex files define Ljavax/inject/Inject;"} AGPBI: {"kind":"SIMPLE","text":"\tat...

Guice: instantiating a singleton before creating the module

java,dependency-injection,guice
Is it possible to instantiate and assign a singleton to a reference with Guice before creating the Module and pass that instance to the Module constructor be bound during configuration? Here is an example of what I mean: I have a method that allows me to create objects depending on...

Spring - should I use @Bean or @Component?

spring,spring-mvc,dependency-injection,autowired
Here is the current code at my work. Method 1 @Configuration public class AppConfig { @Bean @Autowired(required = false) public HttpClient createHttpClient() { // do some connections configuration return new HttpClient(); } @Bean @Autowired public NameClient nameClient(HttpClient httpClient, @Value("${ServiceUrl:NotConfigured}") String serviceUrl) { return new NameClient(httpClient, serviceUrl); } } And the...

Angular service field is undefined for one controller only

javascript,angularjs,dependency-injection,controllers,angular-services
I have defined a simple service: app.service('AuthenticationService', function() { var auth = { isLogged: false }; return auth; }); I use this to set and share the authentication state between controllers. It reads fine in my LoginCtrl: app.controller('LoginCtrl', ['$scope', '$location', '$window', 'UserService', 'AuthenticationService', function LoginCtrl($scope, $location, $window, UserService, AuthenticationService) {...

Injecting EntityManager in servlet, it seems not thread safe

java-ee,servlets,jpa,dependency-injection,entitymanager
I want to make a login app in Java EE. I thought of implementing it using a html page, a servlet and an entity class for the user, but it seems that EntityManager is not thread safe (can't be injected in the servlet and I need it to check the...

what are pitfalls of making UnityContainer not thread safe?

c#,dependency-injection,unity
I am adding dependency injection to my library and I use Unity for that. And I am wondering if I need to take some additional steps to make Unity Container thread-safe. I found couple of articles that are talking about Thread-safe container (example: http://www.fascinatedwithsoftware.com/blog/post/2012/01/04/A-Thread-Safe-Global-Unity-Container.aspx ) but I don't understand if...

Creating interface for concrete class with enum C#?

c#,interface,dependency-injection,enums,separation-of-concerns
Pardon any mistakes, this is one of my first questions. I would really appreciate some guidance here. I tried searching for previous questions, but I couldn't quite word the question correctly. I'm trying to create a simple Logger with an interface class, but I want to have the interface and...

Preventing a class method from executing more than once at a time

c#,asp.net-mvc,dependency-injection,singleton
I have a asp.net mvc controller that when executed calls a method in a service class to open a file and start the import of records into a database. I'd somehow like to restrict this method or class so that another instance can't be created and prevent the method from...

How to register a class with a dependency injected constructor? (SimpleIoC)

c#,dependency-injection,mvvm-light,ioc-container,viewmodellocator
I'm using MVVM Light in my project, but I'm not sure how to register a Viewmodel class in the ViewModelLocator class that takes a parameter in it's constructor. I've looked through the docs on IoC but don't see anything relating to registering a class with a dependency injected constructor, ie...

How to use Guice Module to instantiate one of multiple fields in a class?

java,constructor,dependency-injection,guice
I have a class, and create an instance using a regular constructor: class Foo { String fooName; Bar barObject; ExternalService externalService; Foo(String fooName, Bar barObject, Service someService){ this.fooName = fooName; this.barObject = barObject; this.externalService = externalService; //call to super } } class MyApplication { //instantiate ExternalService ... Foo foo =...

DependencyResolutionException Circular component dependency detected: How to use Autofac to inject decorator?

c#,dependency-injection,mono,decorator,autofac
I have an interface called ILastActivityUpdator as follows: public interface ILastActivityUpdator { void UpdateLastActivity(int userId); } Besides that I have two classes that implement this interface, being LastActivityUpdator and a decorator AnonymousUserLastActivityUpdator. The latter one takes an ICookieProvider as extra argument and uses this in the method implementation. I.e., public...

Dependency injection with unity in a class library project

c#,.net,asp.net-mvc,dependency-injection,unity
I am new with dependency injection pattern. That's why little confused about few things. Scenario: I have a class library project called 'MailCore'. This project has interface and classes that perform all email sending stuff. I have a mvc project 'The site'. It uses the 'MailCore' project to send email....

How do you inject a factory function with Aurelia's DI container?

javascript,dependency-injection,aurelia
I'd like to make a third-party object on the window injectable so that I can test functionality independent of the third-party service. The component I'm trying to build is a simple wrapper around Disqus embedded comments. The factory I would like to use is as simple as () => window.DISQUS...

How to inject resource Class instance in Spring using Dependency injection

java,spring,spring-mvc,dependency-injection,aws-sdk
I am new to Spring. There is a case for which I have written a Class that implements the AutoCloseable interface. Now I want to use it as dependency injection. My concern is if I use @Autowired and later use it in function will Spring automatically close the resource object...

When to use DI over abstract inheritance?

c#,dependency-injection,abstract-class
I am designing a class that uses an abstract property to provide a point of access to a field. Here is a snippet of my code: public abstract class PageBroker : WebBroker { public abstract IPageProvider Provider { get; } } public class ArticleBroker : PageBroker { public override IPageProvider...

Using the container inside a simple bundle class dont work in Symfony 2

php,symfony2,dependency-injection,symfony-2.3
My Error: ContextErrorException: Catchable Fatal Error: Argument 1 passed to Agc\ManagerBundle\Lib\grafica::__construct() must implement interface Symfony\Component\DependencyInjection\ContainerInterface, none given, called in C:\wamp\www\galileo\src\Agc\BackendBundle\Controller\DefaultController.php on line 20 and defined in C:\wamp\www\galileo\src\Agc\ManagerBundle\Lib\grafica.php line 10 My class grafica: <?php namespace Agc\ManagerBundle\Lib; use Symfony\Component\DependencyInjection\ContainerInterface; /** *...

Castle Windsor & Command Pattern

c#,dependency-injection,inversion-of-control,castle-windsor
I am trying to implement a Command, CommandHandler and CommandDispatcher pattern using Castle Windsor without manually asking the container to resolve a CommandHandler based on Command type (which is generally considered an anti-pattern). I found this old article, but the implementation of ITypedFactoryComponentSelector has changed, so now it returns a...

Getting a scoped component from a IDocumentStoreListener

dependency-injection,ravendb,asp.net-5
I have an ASP.NET 5 app using RavenDB, and I'm trying to create an attribute that will create a "Changeset" document with the keys of all the documents that were stored by the action. For that purpose, I created an ActionFilterAttribute instantiated via ServiceFilterAttribute, which is registered as Scoped, that...

Laravel Dependency Injection with inheritance

php,laravel,dependency-injection
Let's say I have the following case: <?php abstract class Service { protected $config; public function __construct($config) { $this->config = $config; } } class ClientService extends Service { } class ProductService extends Service { } Is it possible to register in my service provider the dependency injection for the Abstract...

Ember Simple Auth - injecting current user into every route

ember.js,dependency-injection,ember-simple-auth
I am building a site using Ember Simple Auth. I followed these instructions to try and add the current user object to the session and it worked, using this slightly adapted code: import Ember from 'ember'; import Session from 'simple-auth/session'; export default { name: "current-user", before: "simple-auth", initialize: function(container) {...

How can I retrieve AppSettings configuration back in Asp.Net MVC 6?

c#,dependency-injection,asp.net-mvc-6,appsettings
Assuming that I am using the new DepencyInjection framework to configure my classes and dependencies in the new ASP.Net/vNext. How can I use, How can I get my pre-defined configuration settings? public void ConfigureServices(IServiceCollection services) { // Add Application settings to the services container. services.Configure<AppSettings>(Configuration.GetSubKey("AppSettings")); // Add EF services to...

Is it possible to use Jersey CDI in any JavaSE application?

java,dependency-injection,jersey,jersey-2.0,hk2
I have a interface here interface Idemo{ public int getDemo(int i); } And it's one implementation class DemoImpl implements Idemo{ @Override public int getDemo(int i){ return i+10; } } And there is a class which has a dependency on Idemo class Sample{ @Inject Idemo demo; public int getSample(int i){ return...

Can I specify multiple parameters using WhenInjectedInto for ninject?

.net,dependency-injection,ninject
When setting up my ninject bindings, I'm using the .ToMethod to specify particular parameters for specific connectionstrings, and the WhenInjectedInto method to constrain the binding to specific types: Bind(Of IDbConnection).ToMethod(Function(context) New OracleConnection(ConnectionStringFactory.GetConnection(DBC.ConnectionStrings.Oracle))).WhenInjectedInto(Of AccountBalancesLookup)() Bind(Of IDbConnection).ToMethod(Function(context) New...

Angular Error: [$injector:unpr] Filtering Error

javascript,angularjs,dependency-injection,module
I've got an Angular app that's throwing me this error: Error: [$injector:unpr] http://errors.angularjs.org/1.2.27/$injector/unpr?p0=advFilterNameFilterProvider%20%3C-%20advFilterNameFilter at Error (native) at http://ajax.googleapis.com/ajax/libs/angularjs/1.2.27/angular.min.js:6:450 at http://ajax.googleapis.com/ajax/libs/angularjs/1.2.27/angular.min.js:36:202 at Object.c [as get] (http://ajax.googleapis.com/ajax/libs/angularjs/1.2.27/angular.min.js:34:305) at...

Dependency injection in a revealing module

javascript,unit-testing,dependency-injection
I usually create my javascript "controllers" in the following way: var module = (function(){ function init(someService){ someService.doSomething(); } return { init: init }; })(); module.init(SomeService); I've just stumbled upon dependency injetion in javascript (e.g. JavaScript Dependency Injection). What I would like to know is, from a testing point of view,...

Host TimeLineJS on Meteor app without smart package

meteor,dependency-injection,dependency-management,timeline.js
I'd like to host the TimeLineJS library on my Meteor app locally and not use the smart package because I need to fine tune it. I've tried declaring the createStoryJS function in the Meteor space like this in create Timeline.js. However, there are other dependencies (storyjs-embed.js, storyjs-embed-generator.js, storyjs-embed.js, and everything...

Constructor injection, avoid non-dependency parameters

java,c#,dependency-injection
I need to refactor existing abstract class to implement Dependency Injection, but this class has two constructors that takes other parameters. public abstract class MyClassBase { MyClassBase(int settingId) { _settingId = settingId; } MyClassBase(Setting setting) { _setting = setting; } ... } I need to inject some interfaces and avoid...

Roboblender use annotation databases with multiple modules

android,gradle,dependency-injection,roboguice,roboblender
I'm following the steps from the RoboBlender Wiki to use annotations database but I keep getting java.lang.IllegalStateException: Unable to use annotation database(s) because it cannot find AnnotationDatabaseImpl I am using Android Studio and Gradle. The project consists of multiple modules. app moduleA moduleB moduleC Here is what I added to...

Constructor Injection vs IocFactory

c#,.net,dependency-injection,inversion-of-control
Today at work a collegue and I had a discussion about the following: Basically we have a rule engine which works in the following way: RuleExecutor Gets all rules to execute in the constructor like public RuleExecutor(ICollection<IRule> rulesToExecute) { ... } Executes all rules by calling rule.ApplyRule(); for each rulesToExecute...

Entites count in dependency injection and Repository Pattern

asp.net,asp.net-mvc,dependency-injection,repository-pattern
As a standard we make 'N' controllers for 'N' entities. Let say i have two entities one for student and one for course, i have to add student and add course, if i make interface for class that do crud operations for Student and another interface for class that does...

React dependency injection or similar?

angularjs,dependency-injection,reactjs
In Angular.js it is possible to use dependency injection. I did some browsing and was not able to find an implementation of it. Does React have something similar to that?

Lumen Dependency Injection

php,dependency-injection,lumen
As the last comment of this post it states the following: You can easily do it in any service provider (boot would be a nice place since we can use method based DI). public function boot(\Illuminate\Contracts\Http\Kernel $kernel) { $kernel->appendMiddleware('Sheepy85\L5Localization\Middleware\Localization'); // prependMiddleware works too. } This is Laravel Code for injecting...

Angularjs dependency injection parameter

angularjs,dependency-injection
What is the difference of the below code .factory('Service', ['$log', function($log) {}]); .factory('Service', function($log) {}); both are working fine in my app....

Spring Lookup Method Injection failing with AbstractMethodError

spring,dependency-injection
I have a singleton service class like the below. @Service public class SingletonClass{ @Autowired private ContextProvider provider; public Context run(){ context = provider.createContext(); updateContext(context) } ContextProvider class: public abstract class ContextProvider implements MyInterface{ public abstract Context createContext(); } configuration: <bean name="provider" class="xyz.s.s.ContextProvider" > <lookup-method name="createContext" bean="someBean" /> </bean> <bean id="somebean"...

Dagger 2 - unable to inject object

android,dependency-injection,dagger-2
Im trying to do a very simple dependency injection in a Android app. I am using dagger 2 as a DI tool. The issue is no injection is occuring: here is my code: //behold Motor.java in all its awe. public class Motor { private int rpm; public Motor(){ this.rpm =...

No object available for injection error when using bindFactory

java,dependency-injection,jersey,jersey-2.0,hk2
I have the following implementation for a Jersey (2.18) application: public class RootApplication extends ResourceConfig { public RootApplication() { packages("com.foo.bar"); register(new AbstractBinder() { @Override protected void configure() { bindFactory(RepositoryFactory.class).to(Repository.class); // if I use following line instead of bindFactory it works // bind(OracleRepository.class).to(Repository.class); } }); } public class RepositoryFactory implements Factory<Repository>...

Java Constructor Injection

java,constructor,dependency-injection,instantiation,constructor-injection
Let's say I have a class resources which instantiates all of my OpenGL / Java game objects and I then pass these via constructor to my Scene class (which requires them), like so (simplified example)..... public class Resources { Hero hero; Enemy enemy; MenuButtons mainMenuButtons; Background background; Scene mainMenu; public...

Entity framework object not updating after being passed around

c#,entity-framework,dependency-injection,ninject,.net-4.5
I'm working on setting up a new MVC payment site with a dependency-injected database connection in a separate project, and experimenting with some new things as I do. Currently, I'm trying to load an existing transaction from the database, authorize the card payment, and then save the result back to...

Factory Object or Function, or Pass Unity Container?

c#,dependency-injection,unity,factory,factory-pattern
I have an object that provides a sequence value to various consumers. The provider must manage many sequences, because the consumers could ask to get a new value for any one of the ongoing sequences. All of the sequences follow the same pattern, but they are path dependent and thus...

Module 'ngRoute' is not available

javascript,angularjs,dependency-injection,angularjs-routing
I have linked the script in my index.html, and referenced it in app.js, but I keep getting the error that ngRoute is not available. Any help would be greatly appreciated! app.js angular.module('gameMaster', ['ngRoute', 'castServices']); .config angular.module('gameMaster') .config(function($routeProvider, $locationProvider){ $routeProvider //welcome page .when('/welcome', { templateUrl: '../../../../pages/welcome.html', controller: 'gameController' }) //gameplay page...

PHP dependency property scope

php,oop,dependency-injection,scope
In the following class, I have two properties, $session and $client and these are properties into which dependencies are injected. In the class, they are declared as public but is this the correct scope for properties containing dependencies? What is best practice for PHP in this regard, public, protected or...

How to do database initialization when using DI in Play 2.4?

scala,playframework,dependency-injection,playframework-2.4
Play 2.4 discourages using GlobalSettings.onStart and whole Global object. I'm using play-slick and it has great DI sample in GitHub, but it is missing a example how to do database initialization. How does one implement the database initialization when using DI and when GlobalSettings.onStart is not available? Common cases for...

Dagger 2.0 Constructor injection and Singleton

dependency-injection,dagger-2
is it possible to use Dagger 2.0 Constructor injection and singleton at one time. I don't find the answer in the documentation. Example: @Singleton public class MyClass { private final OtherClass member; @Inject public MyClass(OtherClass member){ this.member = member; } } Constructor injection does work for sure. But is it...

Dependency injection using IOC (Inversion of Control)

c#,interface,dependency-injection,nullreferenceexception
I've Interface public interface IDatabase { void AddRow(string table, string value); } It's implemented on public class Database : IDatabase { public void AddRow(string table,string value) { } } Now here I'm doing Dependency Injection public class CustomerRepository { private readonly IDatabase _database; private readonly string ss; public CustomerRepository() {...

How to use dependency injection for testing?

javascript,dependency-injection
I have piece of code in js like this: var obj = (function(){ var stateObj = {key:"privateValue"}; return { getState: function() { return stateObj.key; }, publicFn : function(){ //do some operation with stateObj if(getState() == "test") { //. . . . } } } }()); and I tested the code...

What is the best way to create Interfaces that are injected into constructor in C#? [closed]

c#,interface,dependency-injection,strategy-pattern
I'm working in a project where external data is fetched from different sources such as database, 3 external web apis, web config. To avoid tight coupling some interfaces are used and passed in my classes constructors, such as: public Dog(IDataAccess dataAccess, IConverter converter, IConfigAccess configAccess, ITimezoneAccess timezoneAccess) public Cat(IDataAccess dataAccess,...

Spring constructor autowiring and intializing other field

java,spring,dependency-injection
I having a Spring class, where I am autowiring a service using constructor, plus in the same constructor I am intializing other field of the same class. @Component class Converter { private TestService testService; private Interger otherFields; @Autowired public Converter(TestService testService) { this.testService = testService; this.otherFields = new Integer(10); }...

SimpleInjector decoration with additional dependency

c#,logging,dependency-injection,decorator,simple-injector
I have a decorator SomethingLoggerDecorator that is supposed to decorate ISomething instances with logging: public class SomethingLoggerDecorator : ISomething { private readonly ISomething decoratee; private readonly ILogger logger; public SomethingLoggerDecorator(ISomething decoratee, ILogger logger) { this.decoratee = decoratee; this.logger = logger; } public void DoSomething() { this.logger.Info("Doing Something"); this.decoratee.DoSomething(); } public...

What's wrong with this factory dependencies issue?

javascript,angularjs,dependency-injection,factory
I'm working with AngularJS. I'd like to get a controller using a first factory which using another one. It could be schematize like that: MyCtrl -> Factory1 -> Factory2 So I tried to do in 3 different files (loaded in the following order): Factory2.js app.factory('Factory2', function () { ... })...

Why a service of main module available in other modules?

angularjs,dependency-injection
I have a main module main which contains a service mainService. I have then injected another module moduleA in my main module. I randomly called mainService in moduleA without injecting main module and was amazed to see it is working fine. angular.module('main', ['moduleA']); angular.module('main').service('mainService', function(){ //insert code here }); angular.module('moduleA',...

Angular module bind priority

angularjs,dependency-injection
If I have an Angular module X that has a dependency on module Y, and both X and Y have a directive that binds to the same event (e.g. "drop"), then will the bind function in my module X directive always get called first? I ran some tests and it...

Inject values of a Map with Guice

java,dependency-injection,guice
I have a Guice managed service that injects a couple of other services. The other services are used depending on a key value that is passed to my service method. So I want to make a Map that maps the service to use to the corresponding key: @Inject private IServiceA...