dependency-injection

Trouble creating a simple singleton class in Jersey 2 using built-in Jersey dependency injection

ぐ巨炮叔叔 提交于 2020-05-09 21:40:53
问题 I am having trouble getting a very basic implementation of a singleton class off the ground with Jersey 2 (2.7) and only Jersey's built-in HK2 dependency injection. I am running this on Tomcat. My goal is to create a singleton instance of a support class that will be used by various web service methods. I don't have a strong preference between constructor injection, method injection, and annotating a class member (as I do below). Here is my to-be-singleton class: package singletest; import

Trouble creating a simple singleton class in Jersey 2 using built-in Jersey dependency injection

爱⌒轻易说出口 提交于 2020-05-09 21:40:19
问题 I am having trouble getting a very basic implementation of a singleton class off the ground with Jersey 2 (2.7) and only Jersey's built-in HK2 dependency injection. I am running this on Tomcat. My goal is to create a singleton instance of a support class that will be used by various web service methods. I don't have a strong preference between constructor injection, method injection, and annotating a class member (as I do below). Here is my to-be-singleton class: package singletest; import

async provider in .net core DI

亡梦爱人 提交于 2020-05-09 20:52:19
问题 I'm just wondering if it's possible to have async/await during DI. Doing the following, the DI fails to resolve my service. services.AddScoped(async provider => { var client = new MyClient(); await client.ConnectAsync(); return client; }); where as the following works perfectly fine. services.AddScoped(provider => { var client = new MyClient(); client.ConnectAsync().Wait(); return client; }); 回答1: Async/await doesn't make sense when resolving dependencies, because: Constructors can't be

Hidden Features of Google Guice [closed]

…衆ロ難τιáo~ 提交于 2020-05-09 17:50:07
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 8 years ago . Google Guice provides some great dependency injection features. I came across the @Nullable feature recently which allows you to mark

Hidden Features of Google Guice [closed]

邮差的信 提交于 2020-05-09 17:49:17
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 8 years ago . Google Guice provides some great dependency injection features. I came across the @Nullable feature recently which allows you to mark

How do I use mocks in some cases but not others in QuarkusTest?

喜欢而已 提交于 2020-04-18 06:57:07
问题 I have two classes in a Quarkus application, let’s call them Service A and Service B. Service B is a dependency of A. When I test ServiceA, I want to mock ServiceB. When I test ServiceB, I want to test the real Service B. I've created a MockServiceB class following this guide on quarkus.io. If I put it in my /test directory, my ServiceATest will properly grab the mock. But so will my ServiceBTest class. How can I selectively inject mocks to different classes? Better yet, can I selectively use

ASP.Net Core Open Partial Generic Dependency Injection

一曲冷凌霜 提交于 2020-04-18 05:21:06
问题 I would like to register the following items for DI using an open generic implementation and interface. I know the following example will not work, as well as other combinations I've tried with MakeGenericType , or GetGenericArguments . I would like to simply call AddRepository<MyDbContext> and then be able to inject my implementation into classes without explicitly having to register the type I am using. Interface public interface IRepository<TEntity> { } Implementation public class

Resolve all implementation/services of a type using .Net Core DI [duplicate]

大城市里の小女人 提交于 2020-04-17 19:06:11
问题 This question already has answers here : How do I see all services that a .NET IServiceProvider can provide? (4 answers) Closed last month . I am working on migration from Asp.Net MVC to .Net Core. In my MVC project we used System.Web.Mvc.DependencyResolver to resolve dependencies which I am trying to replace with .Net Core IServiceProvider However there is one method provided by IDependencyResolver which I am not sure if has any replacement in .Net Core. IEnumerable<object> GetServices(Type

Resolve all implementation/services of a type using .Net Core DI [duplicate]

五迷三道 提交于 2020-04-17 19:05:22
问题 This question already has answers here : How do I see all services that a .NET IServiceProvider can provide? (4 answers) Closed last month . I am working on migration from Asp.Net MVC to .Net Core. In my MVC project we used System.Web.Mvc.DependencyResolver to resolve dependencies which I am trying to replace with .Net Core IServiceProvider However there is one method provided by IDependencyResolver which I am not sure if has any replacement in .Net Core. IEnumerable<object> GetServices(Type

Resolving IEnumerable of generic interfaces from Autofac container

北战南征 提交于 2020-04-11 06:31:47
问题 I'm not sure if this is possible, I've seen some other posts asking similar question but none have a satisfactory answer. What I want to do is resolve a collection of interfaces with differing generic types from Autofac. So constructor of class would look something like this: public class SomeClass<T> where T : class { private readonly IEnumerable<ITestInterface<T>> _testInterfaces; public SomeClass(IEnumerable<ITestInterface<T>> testInterfaces) { _testInterfaces = testInterfaces; } } Ideally