dependency-injection

@Context returns Proxy instead of HttpServletRequest (No thread local value in scope for proxy)

℡╲_俬逩灬. 提交于 2019-12-22 05:08:17
问题 I have a bit of a problem with understanding why @Context dependency injection returns collection of $Proxy(random number) instances instead of HttpServletRequest or HttpServletResponse. I am using Glassfish 3.1.2.2 with it's version of Jersey(Jersey: 1.11.1) and my app is built as EAR application. I have simple @Remote interface where I annotate my methods and REST services work without any problems, but the moment I try to access HttpServletRequest information it just causes problems. I

Ninject Dependency Injection with Asp.Net MVC3 or MVC4

五迷三道 提交于 2019-12-22 05:06:38
问题 I am using Ninject MVC3(version 3.0.0.0) for my ASP.Net MVC3 application installed using NuGet Package for Dependency Injection. Here is the Global.asax change: public class MvcApplication : NinjectHttpApplication { public static void RegisterGlobalFilters(GlobalFilterCollection filters) { filters.Add(new HandleErrorAttribute()); } public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.IgnoreRoute("favicon.ico"); routes.IgnoreRoute

How to do manual DI with deep object graphs and many dependencies properly

断了今生、忘了曾经 提交于 2019-12-22 04:45:17
问题 I believe this questions has been asked in some or the other way but i'm not getting it yet. We do a GWT project and my project leader disallowed to use GIN/Guice as an DI framework (new programmers are not going to understand it, he argued) so I try to do the DI manually. Now I have a problem with deep object graphs. The object hierarchy from the UI looks like this: AppPresenter->DashboardPresenter->GadgetPresenter->GadgetConfigPresenter The GadgetConfigPresenter way down the object

Stack allocated RAII objects vs DI principle

Deadly 提交于 2019-12-22 04:39:10
问题 In C++ I often use RAII-style objects to make code more reliable and allocate them on stack to make code more performant (and to avoid bad_alloc). But creating an object of concrete class on stack violates the dependency inversion (DI) principle and prevents mocking this object. Consider the following code: struct IInputStream { virtual vector<BYTE> read(size_t n) = 0; }; class Connection : public IInputStream { public: Connection(string address); virtual vector<BYTE> read(size_t n) override;

Logging Spring bean creation / dependency injection

眉间皱痕 提交于 2019-12-22 04:29:51
问题 I'm looking for a way to set up Log4j (or any other logger) so that I can see in log whenever Spring creates a bean or sets a bean property. Eg. something like this: 1:00:00 Creating bean Foo (Foo@ef5c94) 1:00:01 Creating bean Bar (Bar@147a87e) 1:00:02 Setting bean Foo (Foo@ef5c94) to Bar (Bar@147a87e) (...) Is this easily possible? I'm using Spring 2.5.6 (no choice there :/ ) and Log4j (version doesn't matter I expect). 回答1: Looks like org.springframework.beans.factory.support

ejb with client artifact - runtime dependency?

血红的双手。 提交于 2019-12-22 04:19:13
问题 Our company creates an ejb in two artifacts. The impl artifact contains the implementations and the client artifact contains all the interfaces. This means that the impl artifact has a compile dependency on the client artifact. Now at runtime, the client artifact needs the impl artifact - otherwise the container cannot inject the required objects. This means that an ear needs to contain the impl artifacts for all client artifacts. Does this mean that the client artifact should have a runtime

How do I inject constants with hk2 in jersey 2.0?

删除回忆录丶 提交于 2019-12-22 04:18:14
问题 How do I inject a constant into some class using HK2 in jersey? With Guice I could have some class like public class DependsOnFoo { @Inject public DependsOnFoo(@Named("FOO") String foo) { ... } ... } and I would configure it in the injector with something like bind(String.class).named("FOO").toInstance(new String("foo")) What's the equivalent, if any, in HK2? 回答1: I'm in the process of learning hk2 coming from Guice. Honestly I am still in the weeds a little with the complexity of hk2 vs the

.NET Core Singleton Creation is called multiple times

跟風遠走 提交于 2019-12-22 04:03:30
问题 I'm registering a service as a singleton in .NET Core. Yet I'm seeing the constructor for the singleton called multiple times. services.AddSingleton<DbAuthorizationOptions, ContextAuthorizationOptions>(); My context authorization options is just Dictionary of Entity Types to IValidators , The context authorization options are passed into the DBContext , to automatically run validations. During the registration of my services, I also register dynamic Validators with my container registered in

Spring - how to inject concrete interface implementation?

梦想与她 提交于 2019-12-22 03:59:29
问题 I need to inject by @Autowired concrete implementation of a service class. Service interface: public interface PostService { ... } Implementation: @Service("postServiceImpl") public class PostServiceImpl implements PostService { ... } Methods in the service are with @ Transactional annotation And now I want to inject postServiceImpl to my controller - because I need to use one method from the implementation, that is not in the interface: @Autowired @Qualifier("postServiceImpl") private

Dependency Injection in a Java 7 standalone application

最后都变了- 提交于 2019-12-22 03:54:30
问题 I would like to use dependency injection in a large Java 7 standalone application, but I am not really sure where to start. I have written a small test application: public class Main { @Inject MyInterface myInterface; public static void main( String[] args ) { Main m = new Main(); System.out.println(m.myInterface.getMessage()); } } with an interface: public interface MyInterface { String getMessage(); } and an interface implementation: @Singleton public class MyInterfaceImpl implements