Skip to main content

All Questions

Filter by
Sorted by
Tagged with
1 vote
1 answer
42 views

In a .NET design, how to combine services (dependency injection) and object with constructors?

We are redesigning an ASP.NET MVC application that has business logic in helpers. We want it to have DI services (passed to controllers by dependency injection). We have 2 concepts that we don't ...
roberth's user avatar
  • 962
0 votes
1 answer
25 views

Dependency injection - data pass to dependency

I'm trying to learn and understand dependency injection. (python example below): class Printer : def print(self): pass class CSVPrinter(Printer) : def print(self, data): for i ...
andrew's user avatar
  • 61
0 votes
1 answer
36 views

When Dependancy Injection goes rouge in blazor

I have a blazor project that has a sperate Webapp UI and a mobile app UI utilising blazor hybrid principals, they share multiple components that display some data and allow actions to be performed on ...
James Rogers's user avatar
1 vote
2 answers
90 views

Angular Service Injection in reusable components

I have a reusable component, ReusableComponent, that needs to use a service that contains an specific function. This service must implement an interface, ServiceAbstraction, to make sure that it ...
Pizzicato's user avatar
  • 1,611
1 vote
1 answer
106 views

Create multiple instances of an angular service

I have an odd requirement. Our's is a single-spa application. In which, the container app would give us a navigation menu on the left (Tree View), and we would create a new instance of the module and ...
Krishna Thota's user avatar
2 votes
3 answers
178 views

Dependency injection or static class for helper class?

In most of my project I create a static class containing all the functions I use all in my project. But when it comes to unit testing, I feel like there's a big flaw in my design, since I can't use ...
Philippe Balleydier's user avatar
0 votes
1 answer
90 views

Can't properly structure a project with a lot of dependencies in Java

I make a Java project and I faced with a serious issue. In my project I have a lot of managers and repositories. I partially solved the problem by referring to the MainApplication class that holds all ...
duebcio's user avatar
0 votes
2 answers
94 views

How to Use Factory Pattern With Dependency Injection and input parameters?

I'm trying to understand how to create an instance of a service (for example, ITransport) with some input config at runtime using the Factory Pattern and Dependency Injection (Microsoft.Extensions....
Taras's user avatar
  • 49
1 vote
1 answer
67 views

Is it a good practice to inject a factory to a class to can create some resources?

I have an application that use a XML file to define some remote servers from where I want to request some files. I use the XML file because I can set N number of servers with N number of files to be ...
Álvaro García's user avatar
1 vote
1 answer
256 views

Dynamic Implementation Selection in .NET Dependency Injection

i have two different implementations for a single interface that i need to register in Dependency injection, and i need to conditionally check which implementation to instantiate at a given moment. i ...
O.Emad's user avatar
  • 11
0 votes
1 answer
66 views

c# - Managing transactions [duplicate]

How to properly implement transactions that span across multiple repositories? Assume we have 2 repositories (transient) internal sealed class UserRepository : IUserRepository { public ...
Azarah's user avatar
  • 1
1 vote
1 answer
50 views

Interfaces injection implementation coding design pattern

I am using interface dependency injection but thinking about how I can make it scalable if one interface has any change. For example: function updateStatistics(Interface myInterface) { ...
J.Kh's user avatar
  • 15
1 vote
1 answer
111 views

Management of multiple implementation of interface in Spring

In my Spring application , I have some interfaces and its implementation public interface Validation(){ boolean validate(); } public interface ValidationLogicA extend Validation(){ } public ...
Tom's user avatar
  • 95
1 vote
2 answers
100 views

How can I define an Interface which includes the methods of my base class as well as the methods in my current class?

I have a base class which includes common CRUD functionality: public class GeneralRepository<T> : IGeneralRepository<T> { private readonly IConfiguration _config; private readonly ...
kj49's user avatar
  • 65
2 votes
0 answers
340 views

What are the advantages of using Depends in FastAPI?

I am studying the FastAPI framework and the principle of Dependency Injection, which is implemented in it using Depends. I have a question related to the expediency of using DI in those cases, which ...
fepex65885's user avatar
1 vote
0 answers
173 views

Dynamic BLoC Implementation Switching in Flutter Using Bloc Pattern and Custom Class Loader

I'm facing a challenge in designing a Flutter application with the BLoC state management pattern. The app is intended to be generic but used by multiple clients, some of whom have specific needs ...
Hedwin's user avatar
  • 411
2 votes
1 answer
69 views

How should I use Factory method design pattern that follows Dependency Inversion Principle

I've created a command like this, but I would like to refactor it to follow the DI principle: public function handle() { $productChoice = $this->argument('product'); if ($productChoice == ...
Ali's user avatar
  • 347
0 votes
2 answers
495 views

Injecting DbContext and Repository into class library service constructor

I'm getting an error using DI in a service located in a different class library to my main blazor application. System.InvalidOperationException: No service for type 'Services.SomeService' has been ...
Derek Mitchell's user avatar
0 votes
2 answers
386 views

Using scoped services (ie DbContext) from two scopes without service locator

I need to write some service with method that needs to perform two units of work, where second one will be preformed even if first failed and was rolled back. Creating and rolling back transaction is ...
Alpedar's user avatar
  • 1,344
1 vote
1 answer
165 views

Service Aggregator In N Tier Architecture Pattern

I develop an N Tier Architecture application You can see at this link At there I have an question. As we know that in classic n tier architecture each service layer consist of many public and private ...
Eyup Can ARSLAN's user avatar
0 votes
1 answer
783 views

How do I make the "builder" design pattern and Spring dependency injection compatible with each other?

How compatible are the "builder" design pattern and Spring dependency injection? Consider this code @Test @Sql(executionPhase = BEFORE_TEST_METHOD, value = BASE_SCRIPT_PATH + "...
Sergey Zolotarev's user avatar
0 votes
2 answers
2k views

C# Two GraphServiceClient singleton instances

In my application (.NET Web API), I need to call Microsoft Graph API using two different credentials set (completely different tenant). When I was using only one, the case was simple - I just did a ...
Kamil Turowski's user avatar
1 vote
0 answers
245 views

How I can mock a class marked as final?

The problem I need to add unit tests to the class SensorClient that contains a pointer to the object of the class VelocitySensor marked as final. And what's important is that I can't modify the ...
dzikidzik's user avatar
0 votes
0 answers
25 views

Injecting and asserting on helper classes and facades?

I have a helper class FooItem that acts as a facade for another class Foo. I'm now creating another class Bar which internally uses FooItem to do its Foo related actions. Since FooItem is a facade, my ...
Brother58697's user avatar
  • 3,113
1 vote
2 answers
196 views

How to delegate a command to the proper handler based on its generic types

Is there a clean way to delegate a command to the proper handler by matching the generic types of the command and result ? public interface Handler<COMMAND, RESULT> { public RESULT handle(...
Jeep87c's user avatar
  • 1,120
0 votes
1 answer
153 views

Dependency injection how to avoid hiding dependencies to stateful objects like a validator [closed]

I would like to have your opinion about such a situation, the code is quite simple to should be easy to follow: @Component class MyService { AusiliaryService ausService; public MyService(...
GionJh's user avatar
  • 2,884
1 vote
1 answer
391 views

How can I inject named delegate function into a factory to resolve dependency in .NET 7

I am working on a .NET 7 c# solution. I have a class library that defines my base interface. For example. public interface IFoo<T1, T2> where T1 : Contract1 where T2 : Contract2 { ...
user1439090's user avatar
3 votes
3 answers
5k views

Dependency injection of One interface multiple implementations

I have following situation: IMachineService with method CreateMachine() and I have service for every kind of machine like MachineServiceTypeA createMachine() and so on... and the same from other side ...
H. Ivanov's user avatar
0 votes
1 answer
35 views

Best Practice Open Close Principle

Please take a look at my class. In it WoW avatars are created. In the constructor method instances of different classes are created. If the program is extended by a new class (e.g. Tauren), the ...
Z.J's user avatar
  • 329
0 votes
0 answers
114 views

@AssistedInjection RecyclerViewAdapter parameters resulting in error

I'm working on a new android project using Dagger, and when I had to make an recycler view item trigger a click event I started having problems where to place my event, this event is pretty simple I'...
guisantogui's user avatar
  • 4,106
2 votes
2 answers
264 views

Is there a difference between the three dependency injection syntaxes in Blazor (.net 7)?

As far as I can tell, all three of these patterns work to inject a DI service in a Blazor (.net 7/C#/Razor) project: @inject NavigationManager NavManager in the Razor component [Inject] private ...
bph's user avatar
  • 59
0 votes
1 answer
498 views

Best Practices Setting Properties based another Class

I'm with a simple doubt, what's best approach to setting properties of a class that depends of the values of another class. So I have this three classes that two of them will be serialized and sent ...
MckPT's user avatar
  • 35
2 votes
0 answers
1k views

Azure Function Isolated: simple way to access ILogger in all classes?

I am using Azure Functions in Isolated mode, .NET 7. I am able to inject a logger into my functions pretty easily by simply adding an ILogger to the constructor of my functions and having the logging ...
drew's user avatar
  • 127
3 votes
1 answer
989 views

.NET - It is possible to use DI with the State Pattern?

I'm studying design patterns in .NET and currently i'm trying to implement the State Pattern. But today i got to a problem and i can't figure out how to fix this situation. I have some state classes, ...
VieiraHeloisa's user avatar
2 votes
2 answers
2k views

Is there a design pattern for the case of too many injected classes/dependencies?

I have a class that does too many things (many responsibilities). E.g. logging, loading data from various databases, methods that are doing extraneous calculation/processing as well as the main ...
Jim's user avatar
  • 4,375
0 votes
1 answer
155 views

Is there a best practice to call a specific function every time before any function in Dart/Flutter?

I am working with singleton pattern, and I have managed the dependency and parameter injections like this: LocalizationClientComponent._(); /// Singleton instance of the [...
Baran's user avatar
  • 394
-1 votes
1 answer
33 views

Is it correct that this DataStore service depends on the Serialization service?

There is a IDataStore interface which has this contract: public interface IDataStore { Task<T> CreateEntity<T>(string entityName, string entityId, T entity); Task<T> ...
EEAH's user avatar
  • 747
4 votes
3 answers
845 views

How to choose the right strategy at runtime when implementing the strategy pattern?

Problem description Consider the following implementation of the strategy pattern: // this is the strategy definition public interface ICalculator { int ComputeResult(int a, int b); } // this is an ...
Enrico Massone's user avatar
1 vote
1 answer
1k views

How to do DI with DbContext that will change connection string in runtime? (C# Net 6)

in my team we have multiple databases, one for every client that works with us. In our API we only work with one database, so we do dependency injection of the DbContext using the connection string ...
JaviScript's user avatar
0 votes
1 answer
624 views

Error in CreateInstance() while dynamically creating object of concrete type in Factory Pattern

I am actually new to design patterns and trying to implement factory pattern with .NET Core. I tried to see couple of posts related to factory pattern and trying to implement it, I have added the ...
Abhijith Nayak's user avatar
0 votes
0 answers
996 views

Dependency Injection C++

So recently I started learning some design patterns. I stuck at Dependency Injection. After few hours of trying to understand it I wrote some code. Could you tell me if this code represents pattern ...
Hubertm998's user avatar
0 votes
1 answer
654 views

Python dependency injection vs composition?

I'm learning python and just wanted to confront two versions of the same code and ask which approach is better. Basically I have the Reputation class which should be bound to each Warrior object. My ...
muhy's user avatar
  • 1
0 votes
0 answers
70 views

Symfony5 non-service classes - how to get services (like EntityManager)

The problem: producer A produces 50 products producer A sells its products through 300+ resellers across the world each reseller demands the product sheets in a different structure/format/...
user13859151's user avatar
1 vote
1 answer
1k views

How to configure dependency injection "many levels down" using .NET built-in DI Container

I have a console .NET core application which uses the Microsoft.Extensions.DependencyInjection library as a dependency injection framework. I want to use this framework to inject a dependency two &...
Dean P's user avatar
  • 2,177
1 vote
0 answers
121 views

What is a good design pattern approach for a somewhat dynamic dependency injection in Swift

Let's say there are three components and their respective dynamic dependencies: struct Component1 { let dependency1: Dependency1 func convertOwnDependenciesToDependency2() -> Dependency2 } ...
ph1psG's user avatar
  • 738
1 vote
1 answer
704 views

Correct way to implement strategy design Pattern in C#

I have a scenario wherein there are multiple conditions and I have to write a code in such a way that it should be open for extension and not for modification so I went with the strategy design ...
Mysterious288's user avatar
0 votes
0 answers
12 views

How do I Inject one interface in another service in spring [duplicate]

I want to Inject one interface in another serviceimpl. @Service class ServiceA implements InterfaceA { //// } @Service class ServiceB implements InterfaceB { @Inject private InterfaceA obj; // ...
Tamil.S's user avatar
  • 463
1 vote
1 answer
29 views

Executing code depending on parameter in controller

So I have this controller code, with dependency injection setup private IManager manager public Controller(IManager manager) { this.manager = manager } Task async GetAsync(string appId) { ...
r0m4n's user avatar
  • 13
1 vote
0 answers
687 views

Strategy pattern in Spring boot application for payment gateway and methods

I have a controller where I am being passed a gatewayid for different providers. I have a BasePaymentService interface which is implemented by Payu service and Razorpay service for now. I want to ...
diaop's user avatar
  • 57
1 vote
2 answers
3k views

C# - How to inject new instance of dependency to a class which get instantiated once in the app lifetime?

Here is a class which will be instantiated only once through out the lifetime of the application public class SampleClass //instantiated only once { public void DoOpertation()//will be called by ...
ecma-402's user avatar

1
2 3 4 5
13