How Can I Register and Manage Services in a Large C# Project?

fatih uyanık 100 Reputation points
2024-10-02T12:49:07.14+00:00

Hello

I will start developing a new C# WPF project. I need your information on something while planning.

I will use the MVVM pattern in the project. I will create a large number of services to perform some tasks and use them in the relevant classes. I am thinking of using the Microsoft.Extension package as a container while doing this. However, in my research I found that the created services should be registered in the container as a dependency and at the same time the classes that request the service should be registered in the container. As this project grows, managing dependencies can cause problems.

How should I structure service management to handle this situation? What is the most trouble-free approach to this? I want the dependencies to be managed automatically.

Thank you.

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,768 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,902 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Bruce (SqlWork.com) 64,826 Reputation points
    2024-10-02T21:08:04.9066667+00:00

    currently there is no automatic registration. each service must be registered via an api call. you could define an interface used to register a component. each component that wants to be registered could implement this interface. at startup use reflection to find all classes with the interface then call the interface for each class.

    0 comments No comments

  2. Shubham Kahar 0 Reputation points
    2024-10-03T09:18:49.25+00:00

    Hi Fatih,
    Use constructor infusion for administrations, bunch them into modules, and influence Scrutor for programmed enrollment. Oversee administration lifetimes cautiously, and consider Lazy<T> for asset weighty administrations. This guarantees adaptable and proficient help the board.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.