dependency-injection

Using mock objects outside of testing, bad practice?

瘦欲@ 提交于 2021-02-07 03:40:28
问题 I'm working on a project where there is a lot of external service messaging. A good way to describe it in only a slightly "hyperbolas" way would be an application where the system has to send messages to the Flicker API, the Facebook API, and the Netflix API. To support disconnected scenarios, logging concerns, developer usability, configuration, etc... I've experimented using an approach which heavily uses generics and expression trees. The end result looks like this: Messenger<NetflixApi>

Using mock objects outside of testing, bad practice?

青春壹個敷衍的年華 提交于 2021-02-07 03:38:16
问题 I'm working on a project where there is a lot of external service messaging. A good way to describe it in only a slightly "hyperbolas" way would be an application where the system has to send messages to the Flicker API, the Facebook API, and the Netflix API. To support disconnected scenarios, logging concerns, developer usability, configuration, etc... I've experimented using an approach which heavily uses generics and expression trees. The end result looks like this: Messenger<NetflixApi>

Spring. Resolve circular dependency with java config and without @Autowired

白昼怎懂夜的黑 提交于 2021-02-06 15:23:05
问题 I've got circular dependency and java config. While resolving it with xml config is very easy I can't resolve it with java config without @Autowired. Beans: public class A { private B b; public B getB() { return b; } public void setB(B b) { this.b = b; } } public class B { private A a; public A getA() { return a; } public void setA(A a) { this.a = a; } } I've tried this(I've read that with @Bean annotation Spring won't invoke method every time bean is referenced, but in this case it's

Implementing Dependency injection static methods

隐身守侯 提交于 2021-02-04 15:45:20
问题 In this old code I am trying to update , they implemented dependency injection like this: public class Program { private IProgramRepository programRepository; public Program(IProgramRepository repository) { this.programRepository = repository; } public Program() : this(new EN_Program()) { } now in this program class all methods are static, so all of the static methods all actually have 2 methods like this: public static List<Program> GetProgramsByUser(int userId) { return GetProgramsByUser

Decorator for creating Scope with ScopedLifestyle.Flowing in Simple Injector

可紊 提交于 2021-01-29 22:27:11
问题 I need some help to understand what it's wrong in my configuration of the container. I based this implementation by using this example. Basically i need to implement some use case as database command based on that interface public interface IDatabaseCommand<TResult, TParam> { TResult Execute(TParam commandParam); } and i want to use a decorator that add the transaction safe functionality. Every command need to use a dedicated DbContext and the transaction has to be executed on that context To

Spring Dependency Injection - Private fields - Anti Pattern? Why does it even work?

允我心安 提交于 2021-01-29 21:33:07
问题 I am generally a c# developer but working on Java now and then I see a lot of dependency injection using Spring on private properties, with no public way of setting the value. I was surprised this actually works, but I guess it’s possible via reflection? Surely this is terrible practice?! I can't see how anyone unit testing or inspecting the class would possibly know that a private member needs to be set from some external framework. How would you even set the property when you are unit

NestJS: Dependency Inyection and Provider Registration

妖精的绣舞 提交于 2021-01-29 19:53:39
问题 Can anyone help me to understand DI Nest Fundamentals, my question: "Is it possible to have a service class without @Injectable annotattion , and also this class does not belong to any module ?" I saw on internet an example like below: This class exists in a common folder: export class NotificationService { constructor( @Inject(Logger) private readonly logger: LoggerService, private readonly appConfigService: AppConfigService, @Inject(HttpService) private readonly httpService: HttpService ) {

Is it possible to add a service from a controller or manager class other than the ConfigureService method

生来就可爱ヽ(ⅴ<●) 提交于 2021-01-29 17:31:05
问题 I want to Use services.AddPredictionEnginePool<..> When I use "IServiceCollection DI" I receive the notification below Cannot instantiate implementation type 'Microsoft.Extensions.DependencyInjection.IServiceCollection' for service type 'Microsoft.Extensions.DependencyInjection.IServiceCollection'. How can I Use this; services.AddPredictionEnginePool<..> From other classes. Why I want do; The reason of the usage of the service is to add a new object in runtime. 回答1: IServiceCollection is the

Can we use simple injector for dependency injection in wcf services and How?

不问归期 提交于 2021-01-29 15:47:14
问题 Can we use simple injector for dependency injection in wcf services 回答1: We can use simple injector for dependency injection in wcf services.Here is my demo. After installing this NuGet package, it must be initialized in the start-up path of the application by calling the SimpleInjectorServiceHostFactory.SetContainer method: protected void Application_Start(object sender, EventArgs e) { var container = new Container(); container.Options.DefaultScopedLifestyle = new AsyncScopedLifestyle();

Compile error on Property Wrapper in Swift 5.1

别来无恙 提交于 2021-01-29 12:27:48
问题 I'm figuring out Property Wrappers in Swift, but I seem to miss something. This is how I wrote a property wrapper for a dependency injection framework we use: @propertyWrapper struct Inject<Value> { var _value: Value var wrappedValue: Value { get { return _value } set { _value = newValue } } init(_ container: Container = AppContainer.shared) { do { _value = try container.resolve(Value.self) } catch let e { fatalError(e.localizedDescription) } } } But when I use it in my class like below, I