dependency-injection

How to specify a classifier in a gradle dependency's dependency?

北慕城南 提交于 2019-12-18 11:00:09
问题 Say I want to add guice-assistedinject as a dependency in my project. It specifies the guice artifact as a dependency itself. How do I tell it to use the no_aop version of guice? I know I can do the following, but can I do it in one step without excluding the guice module? dependencies { compile (group: 'com.google.inject.extensions', name: 'guice-assistedinject', version: '3.0') { exclude module: 'guice' } compile group: 'com.google.inject', name: 'guice', version: '3.0', classifier: 'no_aop

Binding a class to an interface

拈花ヽ惹草 提交于 2019-12-18 10:34:34
问题 Using typescript, I can easily bind classes to themselves: bootstrap(MyAppComponent, [MyClass]); However, I would like to bind my class to an interface, like such: boostrap(MyAppComponent, [???]); such that I can inject it as follows: class MyAppComponent { constructor(my_class : IMyClass){ } }; Is this possible in Angular2? If yes, how to I have to specify the binding? 回答1: To make it short the problem is that Interfaces disappear when typescript is compiled. So you'd have to use @Inject

How to use Dependency Injection without breaking encapsulation?

懵懂的女人 提交于 2019-12-18 10:22:30
问题 How can i perform dependency injection without breaking encapsulation? Using a Dependency Injection example from Wikipedia: public Car { public float getSpeed(); } Note: Other methods and properties (e.g. PushBrake(), PushGas(), SetWheelPosition() ) omitted for clarity This works well; you don't know how my object implements getSpeed - it is " encapsulated ". In reality my object implements getSpeed as: public Car { private m_speed; public float getSpeed( return m_speed; ); } And all is well.

Why is MVC4 using the Service Locator Anti-Pattern?

不问归期 提交于 2019-12-18 10:15:22
问题 After reading "Dependency Injection in .NET" by Mark Seemann I stay away from the Service Locator which is an anti-pattern. Upon reading the release notes on MVC 4 I see: Improved Inversion of Control (IoC) via DependencyResolver: Web API now uses the service locator pattern implemented by MVC’s dependency resolver to obtain instances for many different facilities. Thus I'm left curious and confused why Microsoft would use a service locator in 2012. 回答1: That's an implementation detail that

What is Ninject and when do you use it?

假如想象 提交于 2019-12-18 10:10:46
问题 I have been helping a few friends on a project and there is a class that uses Ninject. I am fairly new to C# and I have no idea what that class is doing, which is why I need to understand Ninject. Can anyone explain what Ninject is and when does one use it(with example if possible)? Or if you can point to some links that would be great too. I tried this question: Ninject tutorials/documentations? but it didn't really help a beginner like me. 回答1: Ninject is dependency injector for .NET,

Is there a list of Symfony2 default container services?

杀马特。学长 韩版系。学妹 提交于 2019-12-18 10:00:32
问题 Here is an example, taken from Symfony2 website, about defining a custom service (YAML notation): services: newsletter_manager: class: %newsletter_manager.class% arguments: [@mailer, @templating] Is there a list of default Symfony2 service objects that can be injected into a custom service as parameters (like @mailer , @templating , @doctrine )? I know that they come from the Container (which is available, for example, in each Controller class). I've tryed to dump all services, but i'm

What is AOP, Dependency Injection and Inversion Of Control in Simple English

和自甴很熟 提交于 2019-12-18 10:00:25
问题 I have tried to understand AOP, Dependency Injection and Inversion of Control SPRING related concepts but I am having hard time understanding it. Can anyone explain this in simple English ? 回答1: I understand your confusion and it took me some time to understand how these concepts were related together. So here is my (somehow personal) explanation of all this: 1. Inversion of Control Inversion of control is a design principle rather generic that refers to the decoupling of the specification of

Unable to inject dependency in Junit test

允我心安 提交于 2019-12-18 09:49:14
问题 Having some trouble injecting a dependency in one of my JUnit test classes. I believe the TestApplication is not package scanning or is not being loaded. Code below: package com.mitto.repositories; import static org.junit.Assert.*; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.TestExecutionListeners; import org

Passive Attributes and Nested Containers

让人想犯罪 __ 提交于 2019-12-18 09:47:12
问题 Final Solution With help from @NightOwl888's answer, here's the final approach I went with for anyone who ends up here: 1) Added the global filter provider: public class GlobalFilterProvider : IFilterProvider { public IEnumerable<Filter> GetFilters(ControllerContext controllerContext, ActionDescriptor actionDescriptor) { var nestedContainer = StructuremapMvc.StructureMapDependencyScope.CurrentNestedContainer; foreach (var filter in nestedContainer.GetAllInstances<IActionFilter>()) { yield

Spring 4.1.5.RELEASE fails to do dependency injection for SessionFactory of Hibernate 4.3.8.Final

断了今生、忘了曾经 提交于 2019-12-18 09:41:48
问题 Question is not a duplicate as Hibernate is involved As the James' answer partially solved the problem, I accepted it and opened a new question, please follow up here I am trying to inject SessionFactory into a repository class; however, it looks like it does not work as the code returns NullPointer exception. I cleaned and rebuilt the project but the issue still exist. I also put @Autowired on the setSessionFactory method but did not help. Interface public interface TestRep { public void get