dependency-injection

Spring IllegalAccessException after isolating a module in a separate ClassLoader

好久不见. 提交于 2021-02-10 17:13:42
问题 I have had a problem involving jar clash between incompatible versions of BouncyCastle. We have solved it by creating a bean that, using a Spring-defined ClassLoader bean injected as property, invokes services from classes not stored in official WEB-INF/lib folder. Following are the beans definitions <bean id="metainfJarClassloader" class="com.jdotsoft.jarloader.JarClassLoaderFactory" factory-method="create"/> <bean id="jadesFactory" class="it.csttech.proxy.jades.JadesFactory"> <constructor

Registering generic type with type constraint in .NET Core (MS.DI)

时光怂恿深爱的人放手 提交于 2021-02-10 14:06:17
问题 I have a generic interface IPipelineBehavior<TRequest, TResponse> (from MediatR). I'm trying to register a specific behavior for this interface as follows: services.AddTransient(typeof(IPipelineBehavior<,>), typeof(ValidationMiddleware<,>)); ValidationMiddleware implements IPipelineBehavior like so: public class ValidationMiddleware<TRequest, TResponse> : IPipelineBehavior<TRequest, Result<TResponse>> Result is a custom class I want all of my MediatR IRequestHandlers to return. When the app

.NET Core Scoped called in Singleton through DI

时光怂恿深爱的人放手 提交于 2021-02-10 12:44:52
问题 I'm getting an error in 2.0 that I used not to get in .Net Core 1.1. Cannot consume scoped service 'ArithmosDaily.Data.ArithmosContext' from singleton 'ArithmosDaily.IHangfireJobSchedulerService'. I am using Hangfire, and I need it to access my database (so I inject my context through DI) to update the database with some data from an API on a schedule. So it appears the DbContext is instantiated as Scoped, and I am setting my Hangfire service as a Singleton. In Core 1.1, there was no check

.NET Core Scoped called in Singleton through DI

孤街浪徒 提交于 2021-02-10 12:42:29
问题 I'm getting an error in 2.0 that I used not to get in .Net Core 1.1. Cannot consume scoped service 'ArithmosDaily.Data.ArithmosContext' from singleton 'ArithmosDaily.IHangfireJobSchedulerService'. I am using Hangfire, and I need it to access my database (so I inject my context through DI) to update the database with some data from an API on a schedule. So it appears the DbContext is instantiated as Scoped, and I am setting my Hangfire service as a Singleton. In Core 1.1, there was no check

Dependency Injection to Play Framework 2.5 modules

試著忘記壹切 提交于 2021-02-10 07:58:05
问题 I have a module class with the following signature: class SilhouetteModule extends AbstractModule with ScalaModule { I would like to inject configuration: class SilhouetteModule @Inject() (configuration: Configuration) extends AbstractModule with ScalaModule { But it fails with the following error. No valid constructors Module [modules.SilhouetteModule] cannot be instantiated. The Play documentation mentions that In most cases, if you need to access Configuration when you create a component,

How can I resolve a decorator using a particular instance of a component or another decorator object in .net core

▼魔方 西西 提交于 2021-02-10 07:01:36
问题 After learning about the Decorator Pattern with typical Coffee example where Decorator Pattern saves us from the class explosion problem, I wrote some code to use and see it myself. Lets take a look at the UML first... and here is the code: Component ICofee defination: public interface ICoffee { string Name { get; } decimal Cost { get; } } LatteCoffee definition: public class LatteCoffee : ICoffee { public string Name { get; } = "Latte"; public decimal Cost => 2.00m; } Decorators

Should I use readonly on injected Angular services instead of making them public?

旧城冷巷雨未停 提交于 2021-02-09 11:45:49
问题 I had a discussion today where some of my colleagues said that they inject their Angular services like that: constructor(readonly language: I18nService) They said they do this because it prevents consumers of my component to change the injected service, kinda like that: @Component({ ... }) class ComponentA { constructor(public language: I18nService) {} } @Component({ ... }) class ComponentB { @ViewChild(ComponentA) compA: ComponentA; constructor() { this.compA.language = new I18nService(); }

How Use shared preference with injectable and get_it in flutter?

江枫思渺然 提交于 2021-02-09 08:59:12
问题 im using injectable and get_it package in flutter i have a shared preference class : @LazySingleton() class SharedPref { final String _token = 'token'; SharedPreferences _pref; SharedPref(this._pref); Future<String> getToken() async { return _pref.getString(_token) ?? ''; } Future<void> setToken(String token) async { await _pref.setString(_token, token); } } this class inject as LazySingleton and i have a module for inject the shared preference : @module abstract class InjectableModule {

Azure function V3 could not load file or assembly Microsoft.Extensions.DependencyInjection.Abstractions, Version=5.0.0.0 with EF core 5.0-rc1

梦想与她 提交于 2021-02-08 13:08:49
问题 Case We are creating azure function v3 with .netcore 3.1. Using EF core 5.0-rc1 and Depdency Injection 1) DependecyInjection [assembly: FunctionsStartup(typeof(xxxxx.Startup))] namespace xxxxx { public class Startup : FunctionsStartup { public override void Configure(IFunctionsHostBuilder builder) { var services = builder.Services; var configBuilder = new ConfigurationBuilder() .SetBasePath(Environment.CurrentDirectory) .AddJsonFile("local.settings.json", true, reloadOnChange: true)

What is the alternative of using Qualifier annotation in XML in Spring?

拈花ヽ惹草 提交于 2021-02-08 08:17:11
问题 In Spring , if there are two bean ids which refer to the same class and we just want to inject values from only one bean, then we normally use the following annotations in conjunction : @Autowired @Qualifier("bean1") How to achieve the same thing using the xml specification ? What is the alternative of using qualifier annotation in xml ? 回答1: Not an exact alternative but you can use autowire-candidate="false" to all those beans which you want to exclude from being autowired apart from the one