Component dependency injection method and device, storage medium and electronic equipment
Through component dependency injection methods, dependencies are parsed using common components and common interfaces, and injecting dependencies at runtime, the problem of strong binding and increased compilation and deployment time caused by component dependencies in C++ programming languages is solved, and higher fault tolerance and compilation efficiency are achieved.
Patent Information
- Application Number
- CN202411973312.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-30
- Publication Date
- 2025-03-21
- Estimated Expiration
- 2044-12-30
AI Technical Summary
During the development of C++ programming language, the dependencies between components lead to increased strong binding and compilation deployment time, increasing the risk of component function abnormalities and reducing compilation efficiency.
Through component dependency injection methods, common components are abstracted, dependencies are obtained using the common interface, dependencies are parsed, and dependencies are injected through the dependency injection mechanism at runtime to reduce static dependencies between components.
It reduces the risk of component abnormality due to code changes, improves the software's fault tolerance and component functions scalability, and reduces the time and cost of compilation and deployment.
Smart Images

Figure CN119668677A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of component dependency injection, and more specifically, to a component dependency injection method, device, storage medium and electronic device. Background Art
[0002] For an application software, its software functions are completed by several business components. For a business component developed based on the C++ programming language (denoted as component A), the realization of its functions needs to rely on certain functions of other business components (denoted as component B).
[0003] In the development process of the C++ programming language, there are two ways of dependency between component A and component B: the first way is reflected in the code, where component A dynamically loads component B by calling system functions and calls the functions of component B through function pointers; the second form is to add a static library reference to component B in the project configuration of the integrated development environment (IDE). In this way, the compiler will automatically find and load the symbol information in component B when compiling the code of component A, thereby determining the dependency.
[0004] However, the first and second methods will bring the following problems: For the first method, the dependency is determined by code calls, which will lead to a strong binding relationship between the two components. If there is a change in component B, it may affect the operation of component A or even compilation, resulting in the risk of functional anomalies between components due to code changes. For the second method, the dependency is established through engineering configuration. This dependency will cause the compilation and deployment of the two components to take extra time, especially for components with complex functions. Even if the dependent components have at least changed a little, they still need to be recompiled and generated when they are compiled and deployed, which often takes a lot of time, thereby reducing the efficiency of component compilation.
[0005] Therefore, how to reduce the risk of malfunction of two interdependent components due to code changes and improve the efficiency of component compilation are problems that need to be urgently solved in this application. Summary of the invention
[0006] In view of this, the present application discloses a component dependency injection method, device, storage medium and electronic device, which aim to reduce the risk of functional abnormalities of two interdependent components due to code changes, improve the fault tolerance of the software, enhance the scalability of component functions, and the efficiency of component compilation.
[0007] In order to achieve the above purpose, the disclosed technical solution is as follows:
[0008] In a first aspect, the present application discloses a component dependency injection method, the method comprising:
[0009] When receiving a business requirement, abstract the software components according to the business requirement to obtain a common component; wherein the common component is composed of a business component that ensures the basic functions of the software and a component that provides public services when the software is running;
[0010] The common component calls the common interface to obtain various dependency information required for dependency injection;
[0011] Analyzing the component dependencies of each dependency information until the dependencies corresponding to each dependency information are obtained;
[0012] When it is monitored that the system component calls the interface of the business component, the dependency item corresponding to the dependency information is injected into the instance of the business component through the dependency injection mechanism to complete the dependency injection process of the component.
[0013] Preferably, when receiving a business requirement, business abstraction is performed on the components of the software according to the business requirement to obtain a common component, including:
[0014] When receiving business requirements, identifying business components that ensure basic software functions and components that provide public services when the software is running according to the business requirements;
[0015] Business components that ensure the basic functions of the software and components that provide public services when the software is running are identified as public components.
[0016] Preferably, the calling of the common interface by the common component to obtain various dependency information required for dependency injection includes:
[0017] Determine the common interface of each business component through pre-defined unified export interface rules;
[0018] Through the common components and system functions, the general interface is called to obtain various dependency information required for dependency injection.
[0019] Preferably, performing component dependency parsing on each dependency information until obtaining a dependency corresponding to each dependency information includes:
[0020] For each dependency information, the internal data structure of the dependency information is traversed by the dependency injection system to obtain a target component; the target component is a component of the dependency instance;
[0021] Obtaining a handle of the target component and a dependency instance name, and caching the handle and the dependency instance name in a temporary data structure;
[0022] Return to execute the step of traversing the internal data structure of the dependency information to obtain the target component, until the handle of the target component corresponding to each dependency information and the dependency instance name are obtained and cached, so as to complete the process of obtaining the dependency corresponding to each dependency information.
[0023] Preferably, when it is monitored that the system component calls the interface of the business component, the dependency item corresponding to the dependency information is injected into the instance of the business component through the dependency injection mechanism to complete the dependency injection process of the component, including:
[0024] When it is detected that a system component calls a business component interface, the dependency corresponding to the business component interface is searched in the dependency injection system;
[0025] Obtaining the instance type name and instance object that the business component depends on from the dependency;
[0026] The instance type name and the instance object are injected into the instance of the business component through the dependency injection system and the public interface corresponding to the public component to complete the dependency injection process of the component.
[0027] Preferably, it also includes:
[0028] When the dependency items corresponding to the dependency information are obtained, it is determined whether the dependency items corresponding to the dependency information have generated their respective corresponding instances;
[0029] If so, store the dependencies of the generated instance into the data structure;
[0030] If not, determine the common interface of the dependency whose instance has not been generated, generate an instance of the dependency through the common interface, and store the dependency of the generated instance in a data structure.
[0031] A second aspect of the present application discloses a component dependency injection device, the device comprising:
[0032] A business abstraction unit is used to perform business abstraction on the software components according to the business requirements when receiving business requirements, so as to obtain common components; wherein the common components are composed of business components that ensure the basic functions of the software and components that provide public services when the software is running;
[0033] An acquisition unit, used to acquire various dependency information required for dependency injection by calling a common interface through the common component;
[0034] A parsing unit, used to parse the component dependencies of each dependency information until the dependency corresponding to each dependency information is obtained;
[0035] The injection unit is used to inject the dependency items corresponding to the dependency information into the instance of the business component through the dependency injection mechanism when it is detected that the system component calls the interface of the business component, so as to complete the dependency injection process of the component.
[0036] Preferably, the business abstraction unit obtains a common component, including:
[0037] An identification module is used to, when receiving a business requirement, identify the business components that ensure the basic functions of the software and the components that provide public services when the software is running according to the business requirement;
[0038] The first determination module is used to determine the business components that ensure the basic functions of the software and the components that provide public services when the software is running as public components.
[0039] A third aspect of the present application discloses a storage medium, which includes stored instructions, wherein when the instructions are executed, a device where the storage medium is located is controlled to execute the component dependency injection method as described in any one of the first aspects.
[0040] The fourth aspect of the present application discloses an electronic device, comprising a memory and one or more instructions, wherein the one or more instructions are stored in the memory and are configured to be executed by one or more processors to perform the component dependency injection method as described in any one of the first aspects.
[0041] It can be seen from the above technical solution that the present application discloses a component dependency injection method, device, storage medium and electronic device. When a business demand is received, the software components are business abstracted according to the business demand to obtain a common component, wherein the common component is composed of a business component that ensures the basic functions of the software and a component that provides public services when the software is running. The common component calls a common interface to obtain various dependency information required for dependency injection, and component dependency items are parsed for each dependency information until the dependency items corresponding to each dependency information are obtained. When it is monitored that the system component calls the interface of the business component, the dependency items corresponding to the dependency information are injected into the instance of the business component through the dependency injection mechanism to complete the component dependency injection process.
[0042] Through the above scheme, when it is detected that the system component calls the interface of the business component, the dependency corresponding to the dependency information is injected into the instance of the business component through the dependency injection mechanism to complete the dependency injection process of the component, so that the business component developed based on the C++ programming language can get rid of the static dependency between components, thereby converting the tight coupling between components into coupling between components and interfaces, that is, the system component and the business component interact through the interface of the fixed public component, reducing the degree of coupling, allowing the component to flexibly select dependencies at runtime, reducing the risk of functional abnormalities of two interdependent components due to code changes, improving the fault tolerance of the software, and enhancing the scalability of component functions. In addition, for components with complex functions, even if the dependent components are changed, they do not need to be recompiled and generated when compiling and deploying. This solution only needs to convert the static dependency between components into the dependency between components and interfaces, thereby realizing the compilation and deployment independence between business components and their dependencies, reducing the cost of compilation and deployment, and improving the efficiency of component compilation. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying any creative work.
[0044] Figure 1 A schematic diagram of a process flow of a component dependency injection method disclosed in an embodiment of the present application;
[0045] Figure 2 This is a schematic diagram of the interface division disclosed in the embodiment of this application;
[0046] Figure 3 A schematic diagram of dependency parsing disclosed in an embodiment of the present application;
[0047] Figure 4 A schematic diagram of the structure of a component dependency injection device disclosed in an embodiment of the present application;
[0048] Figure 5 This is a schematic diagram of the structure of an electronic device disclosed in an embodiment of the present application. DETAILED DESCRIPTION
[0049] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0050] In this application, the terms "comprises", "comprising" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the sentence "comprising a ..." does not exclude the presence of other identical elements in the process, method, article or device comprising the element.
[0051] As can be seen from the background technology, in the development process of C++ programming language, this dependency relationship between component A and component B includes two ways: the first way is reflected in the code, component A dynamically loads component B by calling the system function, and calls the function of component B through the function pointer; the second form is to add the static library reference of component B in the project configuration of the integrated development environment IDE, so that the compiler will automatically find and load the symbol information in component B when compiling the code of component A, thereby determining the dependency relationship. For the first way, determining the dependency relationship by code calling will lead to a strong binding relationship between the two components. If there is a change in component B, it may affect the operation of component A function, or even compilation, resulting in the risk of functional abnormality between components caused by code changes. For the second way, the dependency relationship established by engineering configuration will cause the compilation and deployment of the two components to spend extra time, especially for components with complex functions. Even if its dependent components have at least changed a little, they still need to be recompiled and generated when compiling and deploying, which often takes a lot of time, thereby reducing the efficiency of component compilation. Therefore, how to reduce the risk of malfunction of two interdependent components due to code changes and improve the efficiency of component compilation are problems that need to be urgently solved in this application.
[0052] In order to solve the above problems, the present application discloses a component dependency injection method, device, storage medium and electronic device. When it is monitored that the system component calls the interface of the business component, the dependency information corresponding to the dependency information is injected into the instance of the business component through the dependency injection mechanism to complete the component dependency injection process, so that the business component developed based on the C++ programming language can get rid of the static dependency between components, thereby converting the tight coupling between components into the coupling between components and interfaces, that is, the system component and the business component interact through the interface of the fixed common component, reducing the coupling degree, allowing the component to flexibly select dependencies at runtime, reducing the risk of functional abnormality of two interdependent components due to code changes, improving the fault tolerance of the software, and enhancing the scalability of component functions. And for components with complex functions, even if the dependent components are changed, they do not need to be recompiled and generated when compiling and deploying. This solution only needs to convert the static dependency between components into the dependency between components and interfaces, so as to realize the independent compilation and deployment between the business component and its dependencies, reduce the cost of compilation and deployment, and improve the efficiency of component compilation. The specific implementation method is specifically described by the following embodiments.
[0053] refer to Figure 1 As shown, a component dependency injection method disclosed in an embodiment of the present application is provided, and the component dependency injection method mainly includes the following steps:
[0054] S101: When receiving a business requirement, abstract the software components according to the business requirement to obtain a common component; wherein the common component is composed of a business component that ensures the basic functions of the software and a component that provides public services when the software is running.
[0055] In S101, when business requirements are received, business components that ensure basic software functions and components that provide public services when the software is running are identified according to the business requirements, and the business components that ensure basic software functions and components that provide public services when the software is running are determined as public components.
[0056] Among them, common components are core components used to implement basic functions in the software. These components are used to ensure the most basic functions of the software. Basic functions refer to functions that play a key role in the normal operation of the software and meet the core needs of users in the software system. Basic functions include but are not limited to functions such as buttons, forms, navigation bars, etc.
[0057] A business component is a dll file that implements a business function of the software.
[0058] Before the component dependency injection mechanism based on the C++ programming language, business abstraction is performed on the software components according to business needs.
[0059] First, extract the business components that guarantee the basic functions of the software and the components that provide public services when the software is running as public components. These public components are responsible for implementing the core business of the software and ensuring the normal operation of the basic functions of the software. Since public components are responsible for ensuring the normal operation of the basic functions of the software and providing public services to other components (such as data access, external communication management, etc.), public components need to maintain functional stability. Unless there are defects, try to avoid modifying public components. The access efficiency within the public components is improved by adding interfaces. At the same time, public components should provide a complete interface to facilitate business components to call.
[0060] Secondly, the business functions of the software can be divided according to business needs, and each business function can be abstracted into an interface. The UI functions of the software can also be divided according to the software user interface (UI), and each UI function can be abstracted into an interface. These business interfaces are uniformly deployed by public components. Figure 2 shown. Figure 2 A schematic diagram of interface division is shown.
[0061] Figure 2 It includes software framework and UI. The software framework includes common component layer and business layer.
[0062] Figure 2 In the CommonLayer, it represents the common components mentioned above, which extract the components that maintain the basic functions of the software and the components that provide public services. Figure 2 Only three examples are shown in the figure. The specific component content depends on the software architecture. Reference indicates the mutual reference relationship between public components, that is, public components will reference each other through class instances, interfaces, etc., so as to improve the execution efficiency of the public component layer. Business Layer indicates the specific business part. The components in this part allow users to customize the implementation through the integration interface. Figure 2 Several examples are shown in the figure. For example, HardWare represents the hardware component part. This part provides an IHdwIntf interface to the outside. The implementation of the internal method of the IHdwIntf interface can be customized by the user. When the user customizes the implementation method, the software will use the user-defined implementation method. UI represents the interface part of the software, which can also be customized by the user. Figure 2 Three different UI categories are shown in the figure, each of which provides an external interface for users to inherit and implement.
[0063] S102: Calling a common interface through a common component to obtain various dependency information required for dependency injection.
[0064] In S102, the common interface of each business component is determined by a predefined unified export interface rule, and the common interface is called through common components and system functions to obtain various dependency information required for dependency injection.
[0065] On the basis of S101 above, it is necessary to define unified export interface rules for components. Since C++ itself does not support dynamic dependency injection at runtime, and it is not possible to dynamically obtain the runtime content of dll (such as classes, instances, interfaces, etc.) at runtime through the reflection mechanism like the C# programming language, it is necessary to rely on existing system functions and obtain the dependency information required for dependency injection through additional export interfaces. These interfaces will serve as common interfaces for components. When defining their own interfaces, each business component needs to put the above common interfaces into its own interface file and then provide implementation. For the business functions of the components, each business component needs to inherit and implement a certain business interface. This process is the process of defining unified export interface rules.
[0066] Dependency injection is the process of passing an external component instance required by a component to the target component in some way when the program is running.
[0067] A component is a dynamic runtime library (*dll) that an application depends on to run.
[0068] S103: parse component dependencies for each dependency information until the dependency corresponding to each dependency information is obtained.
[0069] Analyze the component dependencies for each dependency information, as follows Figure 3 As shown, Figure 3 A dependency resolution diagram is shown.
[0070] Specifically, the component dependency items are parsed for each dependency information until the dependency items corresponding to each dependency information are obtained, such as A1-A3 and Figure 3 shown. Figure 3 A dependency resolution diagram is shown.
[0071] A1: For each piece of dependency information, the dependency injection system traverses the internal data structure of the dependency information to obtain the target component; the target component is the component of the dependency (Dependency DLL) instance.
[0072] Based on the C++ dependency injection mechanism, when parsing a business component, the component is first loaded (Load), and then the component name (Dependency Name), interface name, interface version, dependency version (Dependency Version), other related dependencies (SubDependencyInfo) and other information of the current component are obtained through the general interface (Call Specific Interface) and the dependency information acquisition method (Get Dependencyinfo). For each dependency information (Dependency infomation) obtained, the dependency injection system will traverse the internal data structure according to the obtained dependencies, and find (Find Dependency ByInfomation) the target component (public component or system component) that can provide the dependency instance.
[0073] Among them, system components are dll files provided by the operating system to implement certain functions.
[0074] A2: Get the handle of the target component and the instance name of the dependency, and cache the handle and instance name of the dependency in a temporary data structure (Dependency Map).
[0075] If the dependency has been loaded, cache the target component handle and dependency instance name in the Dependency Map.
[0076] A3: If the dependency is not loaded, return to the step of traversing the internal data structure of the dependency information to obtain the target component until the handle of the target component corresponding to each dependency information and the dependency instance name are obtained and cached to complete the process of obtaining the dependency corresponding to each dependency information.
[0077] Once found, the handle of the target component and the name of the dependency instance will be cached in a temporary data structure. If the dependency itself has other dependencies, it will continue to search recursively and then cache until all dependencies are resolved and the dependencies corresponding to each dependency information are obtained.
[0078] When the dependencies corresponding to each dependency information are obtained, determine whether the dependencies corresponding to each dependency information generate their own corresponding instances. If so, store the dependencies of the generated instances in the data structure. If not, determine the common interface of the dependencies that have not generated instances, generate instances of the dependencies through the common interface, and store the dependencies of the generated instances in the data structure.
[0079] Among them, when all dependencies have been resolved, the dependency injection system will look for each dependency to see if the corresponding instance has been generated. If the instance has been generated, it will be obtained directly from the software. If the instance does not exist, it will generate an instance by calling the interface of the component that can provide the instance. Finally, all dependencies of the current component will be saved in the data structure to complete the dependency caching process.
[0080] S104: When it is detected that the system component calls the interface of the business component, the dependency item corresponding to the dependency information is injected into the instance of the business component through the dependency injection mechanism to complete the dependency injection process of the component.
[0081] Specifically, when it is detected that the system component calls the interface of the business component, the dependency item corresponding to the dependency information is injected into the instance of the business component through the dependency injection mechanism to complete the dependency injection process of the component, as shown in B1-B3.
[0082] B1: When it is detected that a system component calls a business component interface, the dependency corresponding to the business component interface is searched in the dependency injection system.
[0083] B2: Get the instance type name and instance object that the business component depends on from the dependencies.
[0084] When a system component calls a business component interface, it first searches the dependency injection system to see if there is a corresponding dependency. If so, it retrieves the dependency information, which includes the instance type name that the current component depends on, and the corresponding instance object.
[0085] Component dependency means that during the operation of component A (dll), it will need the functions provided by other components (component B). In this case, component A is said to be dependent on component B.
[0086] B3: Through the dependency injection system and the public interface corresponding to the public component, the instance type name and instance object are injected into the instance of the business component to complete the dependency injection process of the component.
[0087] When the component is called, the dependency injection system will inject these dependencies into the instance of the current component through the defined public interface, completing the component's dependency injection process.
[0088] The present application provides a component dependency injection mechanism based on the C++ language, defines a set of general interface definition specifications, and a runtime dependency injection mechanism based on C++. A set of general interface definition specifications for the dependency injection mechanism, this set of general interfaces is used to obtain dll dependency related information. The C++ dependency injection mechanism based on the above interface specifications can allow the business components that implement the above interface specifications to dynamically obtain dependency information and inject it during operation. The tight coupling between components is converted into coupling between components and interfaces, and the two components interact through fixed interfaces to reduce the degree of coupling. The static dependency between components (except system components) can be removed, and the two can be compiled, deployed and loaded independently. Thereby reducing the cost of compilation and deployment.
[0089] This application enables business components developed based on C++ to get rid of static dependencies between components, convert static dependencies between components into dependencies between components and interfaces, and allow components to flexibly select dependencies at runtime, reducing the risk of functional abnormalities due to code changes in two interdependent components, namely system components and business components, through fixed common component interfaces, improving the fault tolerance of the software and enhancing the scalability of component functions. By converting static dependencies between components into dependencies between components and interfaces, the compilation and deployment independence between business components and their dependencies is achieved, reducing the cost of compilation and deployment.
[0090] The beneficial effects of the embodiments of the present application are as follows: when it is detected that the system component calls the interface of the business component, the dependency corresponding to the dependency information is injected into the instance of the business component through the dependency injection mechanism to complete the dependency injection process of the component, so that the business component developed based on the C++ programming language can get rid of the static dependency between components, thereby converting the tight coupling between components into coupling between components and interfaces, that is, the system component and the business component interact through the interface of the fixed common component, reducing the degree of coupling, allowing the component to flexibly select dependencies at runtime, reducing the risk of functional anomalies of two interdependent components due to code changes, improving the fault tolerance of the software, and enhancing the scalability of component functions. Moreover, for components with complex functions, even if the dependent components are changed, they do not need to be recompiled and generated when compiling and deploying. This solution only needs to convert the static dependency between components into the dependency between components and interfaces, thereby realizing the independence of compilation and deployment between business components and their dependencies, reducing the cost of compilation and deployment, and improving the efficiency of component compilation.
[0091] Based on the above embodiments Figure 1 A component dependency injection method is disclosed, and an embodiment of the present application also discloses a component dependency injection device, such as Figure 4 As shown, the component dependency injection device includes:
[0092] The business abstraction unit 401 is used to perform business abstraction on the software components according to the business requirements when receiving business requirements to obtain common components; wherein the common components are composed of business components that ensure the basic functions of the software and components that provide public services when the software is running;
[0093] An acquisition unit 402 is used to acquire various dependency information required for dependency injection by calling a common interface through a common component;
[0094] The parsing unit 403 is used to parse the component dependencies of each dependency information until the dependency corresponding to each dependency information is obtained;
[0095] The injection unit 404 is used to inject the dependency items corresponding to the dependency information into the instance of the business component through the dependency injection mechanism when it is detected that the system component calls the interface of the business component, so as to complete the dependency injection process of the component.
[0096] Furthermore, the business abstraction unit 401 includes:
[0097] An identification module is used to identify, when receiving business requirements, business components that ensure basic software functions and components that provide public services when the software is running according to the business requirements;
[0098] The first determination module is used to determine the business components that ensure the basic functions of the software and the components that provide public services when the software is running as public components.
[0099] Furthermore, the acquisition unit 402 includes:
[0100] A second determination module is used to determine the common interface of each business component through a predefined unified export interface rule;
[0101] The first acquisition module is used to call the general interface through public components and system functions to obtain various dependency information required for dependency injection.
[0102] Furthermore, the parsing unit 403 includes:
[0103] A traversal module is used to traverse the internal data structure of each dependency information through the dependency injection system to obtain a target component; the target component is a component of the dependency instance;
[0104] A second acquisition module is used to obtain the handle of the target component and the dependency instance name, and cache the handle and the dependency instance name in a temporary data structure;
[0105] The execution module is used to return to the step of traversing the internal data structure of the dependency information to obtain the target component, until the handle of the target component corresponding to each dependency information and the dependency instance name are obtained and cached, so as to complete the process of obtaining the dependency corresponding to each dependency information.
[0106] Furthermore, the injection unit 404 includes:
[0107] The search module is used to search for the dependencies corresponding to the business component interface in the dependency injection system when it is detected that the system component calls the business component interface;
[0108] The third acquisition module is used to obtain the instance type name and instance object that the business component depends on from the dependency;
[0109] The injection module is used to inject the instance type name and instance object into the instance of the business component through the dependency injection system and the public interface corresponding to the public component to complete the dependency injection process of the component.
[0110] Furthermore, the component dependency injection device also includes:
[0111] A judging unit, configured to judge whether the dependency items corresponding to the respective dependency information generate the respective corresponding instances when the dependency items corresponding to the respective dependency information are obtained;
[0112] A first storage unit, for, if yes, storing the dependencies of the generated instance into a data structure;
[0113] The second storage unit is used to determine the common interface of the dependency of the ungenerated instance if no, generate the instance of the dependency through the common interface, and store the dependency of the generated instance into the data structure.
[0114] The beneficial effects of the embodiments of the present application are as follows: when it is detected that the system component calls the interface of the business component, the dependency corresponding to the dependency information is injected into the instance of the business component through the dependency injection mechanism to complete the dependency injection process of the component, so that the business component developed based on the C++ programming language can get rid of the static dependency between components, thereby converting the tight coupling between components into coupling between components and interfaces, that is, the system component and the business component interact through the interface of the fixed common component, reducing the degree of coupling, allowing the component to flexibly select dependencies at runtime, reducing the risk of functional anomalies of two interdependent components due to code changes, improving the fault tolerance of the software, and enhancing the scalability of component functions. Moreover, for components with complex functions, even if the dependent components are changed, they do not need to be recompiled and generated when compiling and deploying. This solution only needs to convert the static dependency between components into the dependency between components and interfaces, thereby realizing the independence of compilation and deployment between business components and their dependencies, reducing the cost of compilation and deployment, and improving the efficiency of component compilation.
[0115] An embodiment of the present application further provides a storage medium, which includes stored instructions, wherein when the instructions are executed, the device where the storage medium is located is controlled to execute the component dependency injection method as described above.
[0116] The present application also provides an electronic device, whose structural diagram is as follows: Figure 5 As shown, it specifically includes a memory 501 and one or more instructions 502, wherein the one or more instructions 502 are stored in the memory 501 and are configured to be executed by one or more processors 503 to execute the one or more instructions 502 to perform the above-mentioned component dependency injection method.
[0117] For the aforementioned method embodiments, for the sake of simplicity, they are all described as a series of action combinations, but those skilled in the art should be aware that the present application is not limited by the order of the actions described, because according to the present application, some steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the present application.
[0118] It should be noted that each embodiment in this specification is described in a progressive manner, and each embodiment focuses on the differences from other embodiments, and the same or similar parts between the embodiments can be referred to each other. For system embodiments, since they are basically similar to method embodiments, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0119] The steps in the methods of the embodiments of the present application can be adjusted in order, combined, and deleted according to actual needs.
[0120] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are merely used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations.
[0121] The above description of the disclosed embodiments enables those skilled in the art to implement or use the present application. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the scope of the present application. Therefore, the present application will not be limited to the embodiments shown herein, but will conform to the widest scope consistent with the principles and novel features disclosed herein.
[0122] The above is only a preferred implementation of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.
Claims
1. A component dependency injection method, characterized in that: The method comprises: When receiving a business requirement, abstract the software components according to the business requirement to obtain a common component; wherein the common component is composed of a business component that ensures the basic functions of the software and a component that provides public services when the software is running; The common component calls the common interface to obtain various dependency information required for dependency injection; Analyzing the component dependencies of each dependency information until the dependencies corresponding to each dependency information are obtained; When it is monitored that the system component calls the interface of the business component, the dependency item corresponding to the dependency information is injected into the instance of the business component through the dependency injection mechanism to complete the dependency injection process of the component.
2. The method according to claim 1, characterized in that When receiving a business requirement, the software components are abstracted according to the business requirement to obtain a common component, including: When receiving business requirements, identifying business components that ensure basic software functions and components that provide public services when the software is running according to the business requirements; Business components that ensure the basic functions of the software and components that provide public services when the software is running are identified as public components.
3. The method according to claim 1, characterized in that The method of calling the common interface through the common component to obtain various dependency information required for dependency injection includes: Determine the common interface of each business component through pre-defined unified export interface rules; Through the common components and system functions, the general interface is called to obtain various dependency information required for dependency injection.
4. The method according to claim 3, characterized in that The performing component dependency parsing on each dependency information until a dependency corresponding to each dependency information is obtained includes: For each dependency information, the internal data structure of the dependency information is traversed by the dependency injection system to obtain a target component; the target component is a component of the dependency instance; Obtaining a handle of the target component and a dependency instance name, and caching the handle and the dependency instance name in a temporary data structure; Return to execute the step of traversing the internal data structure of the dependency information to obtain the target component, until the handle of the target component corresponding to each dependency information and the dependency instance name are obtained and cached, so as to complete the process of obtaining the dependency corresponding to each dependency information.
5. The method according to claim 1, characterized in that When it is detected that the system component calls the interface of the business component, the dependency item corresponding to the dependency information is injected into the instance of the business component through the dependency injection mechanism to complete the dependency injection process of the component, including: When it is detected that the system component calls the business component interface, the dependency corresponding to the business component interface is searched in the dependency injection system; Obtaining the instance type name and instance object that the business component depends on from the dependency; The instance type name and the instance object are injected into the instance of the business component through the dependency injection system and the public interface corresponding to the public component to complete the dependency injection process of the component.
6. The method according to claim 1, characterized in that Also includes: When the dependency items corresponding to the dependency information are obtained, it is determined whether the dependency items corresponding to the dependency information have generated their respective corresponding instances; If so, store the dependencies of the generated instance into the data structure; If not, determine the common interface of the dependency whose instance has not been generated, generate an instance of the dependency through the common interface, and store the dependency of the generated instance in a data structure.
7. A component dependency injection device, characterized in that: The device comprises: A business abstraction unit is used to perform business abstraction on the software components according to the business requirements when receiving business requirements, so as to obtain common components; wherein the common components are composed of business components that ensure the basic functions of the software and components that provide public services when the software is running; An acquisition unit, used to acquire various dependency information required for dependency injection by calling a common interface through the common component; A parsing unit, used to parse the component dependencies of each dependency information until the dependency corresponding to each dependency information is obtained; The injection unit is used to inject the dependency items corresponding to the dependency information into the instance of the business component through the dependency injection mechanism when it is detected that the system component calls the interface of the business component, so as to complete the dependency injection process of the component.
8. The device according to claim 7, characterized in that The business abstraction unit obtains common components, including: An identification module is used to, when receiving a business requirement, identify the business components that ensure the basic functions of the software and the components that provide public services when the software is running according to the business requirement; The first determination module is used to determine the business components that ensure the basic functions of the software and the components that provide public services when the software is running as public components.
9. A storage medium, characterized in that: The storage medium includes stored instructions, wherein when the instructions are executed, the device where the storage medium is located is controlled to execute the component dependency injection method according to any one of claims 1 to 6.
10. An electronic device, characterized in that: It comprises a memory and one or more instructions, wherein the one or more instructions are stored in the memory and are configured to be executed by one or more processors to execute the component dependency injection method as claimed in any one of claims 1 to 6.
Citation Information
Patent Citations
Component development method and device, electronic equipment and storage medium
CN116149639A
Public dependency item management method for software construction and software construction method
CN116501377A
Software project dependency relationship construction method, device and equipment and readable storage medium
CN117785214A
Dependence injection method, device and system based on Python programming language and medium
CN118092882A
Method and apparatus for dependency injection by static code generation
US20080276231A1