dependency-injection

Spring boot field injection with autowire not working in JUnit test

与世无争的帅哥 提交于 2020-01-10 20:11:14
问题 I want to inject DeMorgenArticleScraper in a test. @RunWith(SpringJUnit4ClassRunner.class) public class DeMorgenArticleScraperTest { @Autowired private DeMorgenArticleScraper deMorgenArticleScraper; ... } The DeMorgenArticleScraper component has some configuration going on for itself, but the IDE/compiler is not complaining about them. @Component public class DeMorgenArticleScraper extends NewsPaperArticleScraper { @Autowired public DeMorgenArticleScraper( @Qualifier(

Inject into private, package or public field or provide a setter?

ぃ、小莉子 提交于 2020-01-10 17:58:13
问题 I see many Java examples using dependency injection with private fields without a public setter like this: public SomeClass { @Inject private SomeResource resource; } But that is a bad idea when the injection should be performed manually for example in unit tests. There are several possibilities to solve this: add a public setter: setSomeResource(SomeResource r) make the field public make the field package protected I'd like to avoid the setter, since nothing really happens in it. So I'd

delphi - how to pass a parameter from the instantiator to a constructor in the spring4d dependency injection framework?

和自甴很熟 提交于 2020-01-10 14:19:06
问题 It's possible to register a class with a parameter expected to be passed from the point of creation? I know it can be done something like this: GlobalContainer.RegisterType<TUserProcessor>.Implements<IUserUpgrader>. AsTransient.DelegateTo( function: TUserProcessor begin Result := TUserProcessor.Create(GetCurrentUser); end ); But there the parameters are binded to the execution context where the container gets registered and not where the object get's intantiated. Something like this it's

Replace Ninject with Simple Injector

假装没事ソ 提交于 2020-01-10 11:33:47
问题 I've used Ninject for my application. Ninject is really simple and easy to learn, but its quite slow and I try to use another IoC to compare if its faster as with Ninject. There are a lot of IoC containers for MVC3 and Simple Injector looks really good to me, but I've a lot of problems with replacting Ninject with Simple Injector. Especially with the AutoMapper . I try to convert this lines into Simple Injector code. Bind<ITypeMapFactory>().To<TypeMapFactory>(); foreach (var mapper in

How can I get a Spring bean injected in my custom Wicket model class?

不想你离开。 提交于 2020-01-10 02:34:08
问题 In a custom Wicket class, not unlike the following, I'm using a service bean which should be injected by Spring, as defined with the SpringBean annotation (from the wicket-spring project). public class ReportExportFileModel extends AbstractReadOnlyModel<File> { @SpringBean(name = "reportService") ReportService reportService; ReportDto reportDto; ReportExportFileModel(ReportDto reportDto) { this.reportDto = reportDto; } @Override public File getObject() { try { return reportService

Guice: is it possible to inject modules?

▼魔方 西西 提交于 2020-01-09 12:52:13
问题 I have a Module that requires some Depedency . Is there a way Modules themselves can be injected? I realize this is a bit of a chicken and egg situation... Example: public class MyModule implements Module { private final Dependency d_; @Inject public MyModule(Dependency d) { d_ = d; } public void configure(Binder b) { } @Provides Something provideSomething() { // this requires d_ } } I suppose in this case the solution would be to turn the @Provides method into a full-fledged Provider

How to free resources and dispose injected service in ASP.NET 5/Core by the end of request?

你。 提交于 2020-01-09 10:01:52
问题 I have a service which is injected into a controller using the ASP.NET Core's default Dependency Injection Container: public class FooBarService : IDisposable { public void Dispose() { ... } } services.AddScoped<FooBarService>(); This creates one instance per request. How to ensure that the framework would dispose the FooBarService instance by the end of each request, without relying on destructors and garbage collection? 回答1: Like the all other DI containers, it will dispose IDisposable

How to free resources and dispose injected service in ASP.NET 5/Core by the end of request?

梦想的初衷 提交于 2020-01-09 10:00:46
问题 I have a service which is injected into a controller using the ASP.NET Core's default Dependency Injection Container: public class FooBarService : IDisposable { public void Dispose() { ... } } services.AddScoped<FooBarService>(); This creates one instance per request. How to ensure that the framework would dispose the FooBarService instance by the end of each request, without relying on destructors and garbage collection? 回答1: Like the all other DI containers, it will dispose IDisposable

How can I log all resolve requests to Autofac container?

亡梦爱人 提交于 2020-01-09 06:20:34
问题 I am trying to debug some problems in a legacy code base. I think is being caused by an exception being thrown because something can't be resolved from the Autofac container. However I think the exception is getting buried somewhere and I am not seeing the root cause. I am sure something is being requested from a controller that either can't be found or something that can be found has a dependency that can't be satisfied. There aren't any guard clauses etc. so I think I am getting a null

Cake pattern with overriding abstract type don't work with Upper Type Bounds

流过昼夜 提交于 2020-01-09 02:29:04
问题 I want to override abstract type in trait with <: and not with = (like answer here Scala Upper Bounds : value is not a member of type parameter). I want to use cake pattern, but this doesn't work, i don't understand why ? trait A { def ping = println("ping") } trait Cake { type T } trait S { this: Cake => type T = A def t: T t.ping } OK, this example run, but in my real use case i want to override type with <: and not with = .It seems impossible to access the t function, why ? trait S { this: