A component dependency injection method, apparatus, storage medium, and electronic device.
By using dependency injection, the tight coupling between components is transformed into coupling between components and interfaces, which solves the problems of functional abnormalities and low compilation efficiency caused by component dependencies in the C++ programming language, and achieves higher fault tolerance and compilation efficiency.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-30
- Publication Date
- 2026-04-03
AI Technical Summary
In the C++ programming language, dependencies between components can lead to a high risk of functional abnormalities due to code modifications, and result in low compilation and deployment efficiency.
By using dependency injection, dependency information is injected into instances of business components, transforming the tight coupling between components into coupling between components and interfaces, reducing coupling and allowing components to flexibly select dependencies at runtime.
It reduces the risk of functional abnormalities caused by code modifications, improves the fault tolerance of the software and the scalability of components, and reduces the cost and time of compilation and deployment.
Smart Images

Figure CN119668677B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of component dependency injection technology, and more specifically, to a component dependency injection method, apparatus, storage medium, and electronic device. Background Technology
[0002] For an application software, its software functions are jointly accomplished by several business components. For a business component developed based on the C++ programming language (denoted as component A), the implementation of its functions depends on certain functions of other business components (denoted as component B).
[0003] In the development process of the C++ programming language, the dependency relationship between component A and component B can be manifested in two ways: The first way is reflected in the code, where component A dynamically loads component B by calling system functions and calls the functionality of component B through function pointers; the second way is to add a static library reference of component B in the project configuration of the integrated development environment (IDE). In this way, when the compiler compiles the code of component A, it will automatically find and load the symbol information in component B, thereby determining the dependency relationship.
[0004] However, both the first and second methods present the following problems: The first method, establishing dependencies through code calls, leads to a strong binding between the two components. If component B is modified, it may affect the operation or even compilation of component A, resulting in the risk of functional abnormalities between components due to code changes. The second method, establishing dependencies through project configuration, causes additional time to be spent on compiling and deploying the two components. This is especially true for complex components; even if their dependent components have undergone minimal changes, recompilation and deployment are still required, often consuming significant time and reducing component compilation efficiency.
[0005] Therefore, how to reduce the risk of two interdependent components malfunctioning due to code changes, and how to improve the efficiency of component compilation, are the problems that this application urgently needs to solve. Summary of the Invention
[0006] In view of this, this application discloses a component dependency injection method, apparatus, storage medium, and electronic device, which aims to reduce the risk of two interdependent components malfunctioning due to code changes, improve the fault tolerance of the software, enhance the extensibility of component functions, and improve the efficiency of component compilation.
[0007] To achieve the above objectives, the disclosed technical solution is as follows:
[0008] The first aspect of this application discloses a component dependency injection method, the method comprising:
[0009] When a business requirement is received, the software components are abstracted according to the business requirement to obtain a common component; wherein, the common component consists of business components that guarantee the basic functions of the software and components that provide common services during software operation;
[0010] The common components call the general interface to obtain the various dependency information required for dependency injection.
[0011] Component dependency parsing is performed on each dependency information until the dependency corresponding to each dependency information is obtained;
[0012] When a system component is detected calling an interface of a business component, the dependency items corresponding to the dependency information are injected into the instance of the business component through a dependency injection mechanism to complete the dependency injection process of the component.
[0013] Preferably, when a business requirement is received, the software components are abstracted according to the business requirement to obtain common components, including:
[0014] When a business requirement is received, the business components that ensure the basic functions of the software and the components that provide public services during software operation are identified based on the business requirement.
[0015] Business components that ensure the basic functions of the software, as well as components that provide public services during software operation, are identified as public components.
[0016] Preferably, the step of obtaining the various dependency information required for dependency injection by calling the general interface through the public component includes:
[0017] The common interfaces for each business component are determined by predefined unified export interface rules;
[0018] The common components and system functions are used to call the general interface to obtain the various dependency information required for dependency injection.
[0019] Preferably, the step of parsing the component dependencies of each dependency information until the dependency corresponding to each dependency information is obtained includes:
[0020] For each dependency information, the internal data structure of the dependency information is traversed through the dependency injection system to obtain the target component; the target component is a component of the dependency instance.
[0021] Obtain the handle of the target component and the name of its dependency instance, and cache the handle and the name of its dependency instance in a temporary data structure;
[0022] 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.
[0023] Preferably, when a system component is detected calling an interface of a business component, the dependency items corresponding to the dependency information are injected into the instance of the business component through a dependency injection mechanism to complete the dependency injection process of the component, including:
[0024] When a system component is detected calling a business component interface, the dependency corresponding to the business component interface is searched in the dependency injection system.
[0025] Obtain the instance type name and instance object that the business component depends on from the dependencies;
[0026] The dependency injection process of the component is completed by injecting the instance type name and the instance object into the instance of the business component through the dependency injection system and the public interface corresponding to the public component.
[0027] Preferred options also include:
[0028] When the dependencies corresponding to each dependency information are obtained, it is determined whether the corresponding dependency of each dependency information generates its own instance.
[0029] If so, store the dependencies for generating the instance in the data structure;
[0030] If not, determine the generic interface for the dependency that has not been instantiated, generate an instance of the dependency through the generic interface, and store the dependency with the generated instance in the data structure.
[0031] A second aspect of this application discloses a component dependency injection apparatus, the apparatus comprising:
[0032] A business abstraction unit is used to abstract the software components according to the business requirements when a business requirement is received, so as to obtain common components; wherein, the common components consist of business components that guarantee the basic functions of the software and components that provide common services during software operation;
[0033] The acquisition unit is used to obtain the various dependency information required for dependency injection by calling the general interface through the public component;
[0034] The parsing unit is 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 dependencies corresponding to the dependency information into the instance of the business component through the dependency injection mechanism when 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 yields common components, including:
[0037] The identification module is used to identify, upon receiving a business requirement, the business components that ensure the basic functions of the software and the components that provide public services during software operation, based on the business requirement.
[0038] The first determination module is used to determine the business components that guarantee the basic functions of the software and the components that provide public services during the software operation as public components.
[0039] A third aspect of this application discloses a storage medium comprising stored instructions, wherein, when the instructions are executed, the device in which the storage medium resides is controlled to perform a component dependency injection method as described in any one of the first aspects.
[0040] The fourth aspect of this application discloses an electronic device including a memory and one or more instructions, wherein one or more instructions are stored in the memory and configured to be executed by one or more processors using the component dependency injection method as described in any of the first aspects.
[0041] As can be seen from the above technical solution, this application discloses a component dependency injection method, apparatus, storage medium, and electronic device. When a business requirement is received, the software components are abstracted according to the business requirement to obtain a common component. The common component consists of business components that guarantee the basic functions of the software and components that provide public services during software runtime. The common component calls a general interface to obtain the various dependency information required for dependency injection. The component dependency item is parsed for each dependency information until the dependency item corresponding to each dependency information is obtained. When it is detected that a system component calls the interface of a 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 component dependency injection process.
[0042] The above solution, when a system component calls a business component's interface, injects the corresponding dependencies into the business component instance via dependency injection. This completes the dependency injection process, allowing business components developed in C++ to break free from static dependencies. This transforms the tight coupling between components into coupling between components and interfaces. System and business components interact through fixed, common component interfaces, reducing coupling and allowing components to flexibly choose dependencies at runtime. This lowers the risk of functional abnormalities due to code changes in interdependent components, improves software fault tolerance, and enhances component scalability. Furthermore, for complex components, even if dependent components change, recompilation is unnecessary during deployment. This solution simply converts static dependencies between components into dependencies between components and interfaces, achieving independent compilation and deployment between business components and their dependencies, reducing compilation and deployment costs, and improving component compilation efficiency. Attached Figure Description
[0043] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of this application. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.
[0044] Figure 1 This is a flowchart illustrating a component dependency injection method disclosed in an embodiment of this application;
[0045] Figure 2 This is a schematic diagram of the interface division disclosed in an embodiment of this application;
[0046] Figure 3 This is a schematic diagram illustrating dependency resolution as disclosed in an embodiment of this application;
[0047] Figure 4 This is a schematic diagram of the structure of a component dependency injection device disclosed in an embodiment of this application;
[0048] Figure 5 This is a schematic diagram of the structure of the electronic device disclosed in the embodiments of this application. Detailed Implementation
[0049] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0050] In this application, the terms "comprising," "including," or any other variations thereof are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0051] As the background technology indicates, in the development process of the C++ programming language, the dependency relationship between component A and component B can take two forms: The first is reflected in the code, where component A dynamically loads component B by calling system functions and invokes component B's functionality through function pointers; the second is added to the project configuration of the integrated development environment (IDE) by including a static library reference for component B. In this way, the compiler automatically searches for and loads the symbol information in component B when compiling component A's code, thus determining the dependency relationship. For the first method, determining the dependency through code calls leads to a strong binding relationship between the two components. If there are changes to component B, it may affect the operation of component A's functionality, or even its compilation, leading to the risk of functional abnormalities between components due to code changes. For the second method, the dependency relationship established through project configuration, this dependency relationship causes additional time to compile and deploy the two components. Especially for components with complex functionality, even if the dependent components have only undergone minor changes, recompilation and deployment are still required, which often consumes a significant amount of time, thus reducing the efficiency of component compilation. Therefore, how to reduce the risk of two interdependent components malfunctioning due to code changes, and how to improve the efficiency of component compilation, are the problems that this application urgently needs to solve.
[0052] To address the aforementioned issues, this application discloses a component dependency injection method, apparatus, storage medium, and electronic device. When a system component calls the interface of a business component, the dependency injection mechanism injects the corresponding dependencies into the instance of the business component, completing the dependency injection process. This allows business components developed using the C++ programming language to break free from static dependencies between components, transforming the tight coupling between components into coupling between components and interfaces. System components and business components interact through fixed, common component interfaces, reducing coupling and allowing components to flexibly select dependencies at runtime. This reduces the risk of functional abnormalities in two interdependent components due to code modifications, improves software fault tolerance, and enhances component scalability. Furthermore, for complex components, even if dependent components are modified, recompilation is not required during compilation and deployment. This solution simply converts static dependencies between components into dependencies between components and interfaces, achieving independent compilation and deployment between business components and their dependencies, reducing compilation and deployment costs, and improving component compilation efficiency. Specific implementation methods are described in detail in the following embodiments.
[0053] refer to Figure 1 The image shows a component dependency injection method disclosed in an embodiment of this application. This component dependency injection method mainly includes the following steps:
[0054] S101: When a business requirement is received, the software components are abstracted according to the business requirement to obtain common components; among them, the common components consist of business components that guarantee the basic functions of the software and components that provide common services during software operation.
[0055] In S101, when a business requirement is received, the business components that guarantee the basic functions of the software and the components that provide common services during software operation are identified based on the business requirement. The business components that guarantee the basic functions of the software and the components that provide common services during software operation are identified as common components.
[0056] Common components are the core components in software used to implement basic functions. These components ensure the software's most fundamental functionality. Basic functions refer to those functions within a software system that play a crucial role in the software's normal operation and in meeting core user needs. Basic functions include, but are not limited to, features such as buttons, forms, and navigation bars.
[0057] A business component is a DLL file that implements a specific business function of the software.
[0058] Before the component dependency injection mechanism based on the C++ programming language, the software components are abstracted according to business requirements.
[0059] First, the business components that ensure the basic functionality of the software, as well as components that provide common services during software runtime, are extracted as common components. These common components are responsible for implementing the core business logic of the software and ensuring the normal operation of its basic functions. Since these common components are responsible for ensuring the normal operation of the software's basic functions and providing common services to other components (e.g., data access, external communication management), they need to maintain functional stability. Modification of common components should be avoided as much as possible unless defects are found. Internally, the access efficiency of common components is improved by adding interfaces. At the same time, common components should provide comprehensive interfaces to facilitate calls by business components.
[0060] Secondly, the software's business functions are divided according to business requirements. Each business function is abstracted into an interface. Alternatively, the software's UI functions can be divided into interfaces, with each UI function abstracted into an interface. These business interfaces are uniformly called by common components. The specific steps for dividing the software's business functions according to business requirements are as follows: Figure 2 As shown. Figure 2 A schematic diagram of interface division is shown.
[0061] Figure 2 This includes the software framework and the UI. The software framework includes a common component layer and a business layer.
[0062] Figure 2 In this context, CommonLayer refers to the common component section mentioned above. This section extracts the components that maintain the basic functions of the software as well as the components that provide common services. Figure 2 Only three examples are shown here; the specific component content depends on the software architecture. Reference indicates the mutual reference relationship between common components, that is, common components will reference each other through class instances, interfaces, etc., in order to improve the execution efficiency of the common component layer. BusinessLayer represents the specific business part, and the components in this part allow users to customize their implementation through integration interfaces. Figure 2 The example shows several things, such as: HardWare represents the hardware component, which provides an IHdwIntf interface. The IHdwIntf interface can be implemented by the user, and the software will use the user-defined implementation. UI represents the software interface, which can also be implemented by the user. Figure 2 The document showcases three different UI categories, each providing an external interface for users to inherit and implement.
[0063] S102: Obtain the various dependency information required for dependency injection by calling the common interface through the public component.
[0064] In S102, the common interface of each business component is determined by predefined unified export interface rules. Through public components and system functions, the common interface is called to obtain the various dependency information required for dependency injection.
[0065] Building upon S101 above, a unified export interface rule for components needs to be defined. Since C++ itself does not support runtime dynamic dependency injection, and unlike C#, it cannot dynamically obtain runtime content (such as classes, instances, interfaces, etc.) of a DLL at runtime through reflection, 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 the common interfaces for components. Each business component, when defining its own interface, needs to include these common interfaces in its own interface file and then provide an implementation. For the business functionality of a component, each business component needs to inherit and implement a specific business interface. This process is what defines the unified export interface rule.
[0066] Dependency injection is the process at runtime of passing an external component instance that a component needs to a target component to that component in some way.
[0067] A component is a dynamic runtime library (*dll) that an application depends on to run.
[0068] S103: Perform component dependency parsing on each dependency information until the dependency corresponding to each dependency information is obtained.
[0069] Component dependency resolution is performed on each dependency, specifically as follows: Figure 3 As shown, Figure 3 A diagram illustrating dependency resolution is shown.
[0070] Specifically, this involves parsing component dependencies for each piece of dependency information until the corresponding dependencies are obtained, such as A1-A3 and... Figure 3 As shown. Figure 3 A diagram illustrating dependency resolution is shown.
[0071] A1: For each dependency information, the target component is obtained by traversing the internal data structure of the dependency information through the dependency injection system; 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. Then, through the general interface (Call Specific Interface) and the method to obtain dependency information (Get DependencyInfo), the system obtains information such as the component name, interface name, interface version, dependency version, and other related dependencies (SubDependencyInfo). For each obtained dependency information, the dependency injection system traverses the internal data structure to find the target component (public component or system component) that can provide an instance of the dependency.
[0073] System components are DLL files provided by the operating system that implement certain functions.
[0074] A2: Obtain the handle of the target component and the instance name of its dependency, and cache the handle and instance name in a temporary data structure (Dependency Map).
[0075] If the dependency has been loaded, cache the handle of the target component and the name of the dependency instance 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, so as 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, the search will continue recursively and iteratively, and then cached, until all dependencies have been parsed and the dependencies corresponding to each dependency information are obtained.
[0078] When the dependencies corresponding to each dependency information are obtained, it is determined whether each dependency has generated its own instance. If so, the dependency with the generated instance is stored in the data structure. If not, the general interface of the dependency without the generated instance is determined, and the instance of the dependency is generated through the general interface. The dependency with the generated instance is then stored in the data structure.
[0079] Once all dependencies have been resolved, the dependency injection system checks each dependency to see if a corresponding instance has been generated. If an instance has been generated, it retrieves the instance directly from the software. If no instance exists, it calls the interface of the component that provides the instance to generate an instance. Finally, it stores all dependencies of the current component in a data structure to complete the dependency caching process.
[0080] S104: When it is detected that a system component calls the interface of a 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 dependency injection process of the component.
[0081] Specifically, when a system component is detected calling the interface of a business component, the dependency injection mechanism is used to inject the corresponding dependency into the instance of the business component to complete the dependency injection process of the component, as shown in B1-B3.
[0082] B1: When a system component is detected calling a business component interface, the dependency corresponding to the business component interface is searched in the dependency injection system.
[0083] B2: Retrieve the instance type name and instance object that the business component depends on from the dependencies.
[0084] When a system component calls an interface of a business component, it first checks 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, as well as the corresponding instance object.
[0085] Component dependency refers to a situation where component A (dll) requires functionality provided by other components (component B) during its operation; in this case, component A is said to depend on component B.
[0086] B3: By using 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 invoked, the dependency injection system will inject these dependencies into the current component instance through the predefined public interface, thus completing the component's dependency injection process.
[0088] This application provides a component dependency injection mechanism based on the C++ language, defining a set of general interface definition specifications and a runtime dependency injection mechanism based on C++. The general interface definition specifications are used to obtain DLL dependency information. Based on these interface specifications, the C++ dependency injection mechanism allows business components implementing these specifications to dynamically obtain and inject dependency information at runtime. It transforms the tight coupling between components into coupling between components and interfaces, with two components interacting through fixed interfaces, reducing coupling. It eliminates static dependencies between components (except for system components), allowing them to be compiled, deployed, and loaded independently, thereby reducing compilation and deployment costs.
[0089] This application enables business components developed in C++ to eliminate static dependencies between components. Static dependencies between components are transformed into dependencies between components and interfaces. This allows components to flexibly select dependencies at runtime, reducing the risk of functional abnormalities due to code changes in two interdependent components—system components and business components—that rely on fixed public component interfaces. This improves software fault tolerance and enhances component extensibility. By converting static dependencies between components into dependencies between components and interfaces, compilation and deployment become independent between business components and their dependencies, reducing compilation and deployment costs.
[0090] The beneficial effects of this application's embodiments are as follows: When a system component calls the interface of a business component, the dependency injection mechanism injects the corresponding dependency items into the instance of the business component to complete the dependency injection process. This allows business components developed based on the C++ programming language to break free from static dependencies between components, thereby transforming the tight coupling between components into coupling between components and interfaces. That is, system components and business components interact through fixed public component interfaces, reducing coupling and allowing components to flexibly select dependencies at runtime. This reduces the risk of functional abnormalities in two interdependent components due to code modifications, improves software fault tolerance, and enhances the scalability of component functionality. Furthermore, for components with complex functions, even if dependent components are modified, recompilation is not required during compilation and deployment. This solution only needs to convert static dependencies between components into dependencies between components and interfaces, achieving independent compilation and deployment between business components and their dependencies, reducing compilation and deployment costs, and improving component compilation efficiency.
[0091] Based on the above embodiments Figure 1 The present application discloses a component dependency injection method and a corresponding 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 abstract the software components according to the business requirements when a business requirement is received, so as to obtain a common component; wherein, the common component consists of business components that guarantee the basic functions of the software and components that provide common services during the software operation.
[0093] The acquisition unit 402 is used to obtain the various dependency information required for dependency injection by calling the common interface through the public component;
[0094] The parsing unit 403 is used to parse the component dependencies of each dependency information until the dependencies corresponding to each dependency information are 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 the system component calls the interface of the business component, so as to complete the dependency injection process of the component.
[0096] Furthermore, business abstraction unit 401 includes:
[0097] The identification module is used to identify, upon receiving a business requirement, the business components that ensure the basic functions of the software and the components that provide public services during software operation, based on the business requirement.
[0098] The first determination module is used to determine the business components that guarantee the basic functions of the software and the components that provide public services during the software operation as public components.
[0099] Furthermore, the acquisition unit 402 includes:
[0100] The second determination module is used to determine the common interface of each business component through predefined unified export interface rules;
[0101] The first acquisition module is used to obtain the various dependency information required for dependency injection by calling common interfaces through public components and system functions.
[0102] Furthermore, the parsing unit 403 includes:
[0103] The traversal module is used to traverse the internal data structure of each dependency information through the dependency injection system to obtain the target component; the target component is the component of the dependency instance.
[0104] The second acquisition module is used to acquire the handle of the target component and the name of the dependency instance, and cache the handle and the name of the dependency instance in a temporary data structure;
[0105] The execution module is used to return the internal data structure for traversing 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 lookup module is used to search for the dependencies corresponding to the business component interfaces in the dependency injection system when a system component calls a 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 dependencies;
[0109] The injection module is used to inject instance type names and instance objects into instances of business components through the dependency injection system and the public interfaces corresponding to public components, so as to complete the dependency injection process of the components.
[0110] Furthermore, the component dependency injection device also includes:
[0111] The judgment unit is used to determine whether each dependency item corresponding to each dependency item should generate its own corresponding instance when the dependency items corresponding to each dependency item are obtained.
[0112] The first storage unit is used, if so, to store the dependencies for generating the instance into the data structure;
[0113] The second storage unit is used to determine, if not, the general interface of the dependency that has not been instantiated, and to generate an instance of the dependency through the general interface, and to store the dependency of the instantiated dependency in the data structure.
[0114] The beneficial effects of this application's embodiments are as follows: When a system component calls the interface of a business component, the dependency injection mechanism injects the corresponding dependency items into the instance of the business component to complete the dependency injection process. This allows business components developed based on the C++ programming language to break free from static dependencies between components, thereby transforming the tight coupling between components into coupling between components and interfaces. That is, system components and business components interact through fixed public component interfaces, reducing coupling and allowing components to flexibly select dependencies at runtime. This reduces the risk of functional abnormalities in two interdependent components due to code modifications, improves software fault tolerance, and enhances the scalability of component functionality. Furthermore, for components with complex functions, even if dependent components are modified, recompilation is not required during compilation and deployment. This solution only needs to convert static dependencies between components into dependencies between components and interfaces, achieving independent compilation and deployment between business components and their dependencies, reducing compilation and deployment costs, and improving component compilation efficiency.
[0115] This application embodiment also provides a storage medium, the storage medium including 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] This application also provides an electronic device, the structural schematic diagram of which is shown below. Figure 5 As shown, it specifically includes a memory 501 and one or more instructions 502, wherein one or more instructions 502 are stored in the memory 501 and are configured to be executed by one or more processors 503 to perform the above-mentioned component dependency injection method.
[0117] For the foregoing method embodiments, in order to simplify the description, they are all described as a series of actions. However, those skilled in the art should understand that this application is not limited to the described order of actions, because according to this application, some steps can be performed in other orders or simultaneously. Furthermore, those skilled in the art should also understand that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily essential to this application.
[0118] It should be noted that the various embodiments in this specification are described in a progressive manner, with each embodiment focusing on the differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For system-type embodiments, since they are basically similar to method embodiments, the description is relatively simple; relevant parts can be referred to the descriptions in the method embodiments.
[0119] The steps in the methods of the various embodiments of this application can be adjusted, combined, or deleted according to actual needs.
[0120] Finally, it should be noted that in this paper, relational terms such as first and second are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations.
[0121] The above description of the disclosed embodiments enables those skilled in the art to make or use this application. Various modifications to these embodiments will be readily 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 this application. Therefore, this application is not to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.
[0122] The above description is only a preferred embodiment of this application. It should be noted that for those skilled in the art, several improvements and modifications can be made without departing from the principle of this application, and these improvements and modifications should also be considered within the scope of protection of this application.
Claims
1. A component dependency injection method, characterized in that, The method includes: When a business requirement is received, the software components are abstracted according to the business requirement to obtain a common component; wherein, the common component consists of business components that guarantee the basic functions of the software and components that provide common services during software operation; The common components call a general interface to obtain the various dependency information required for dependency injection, including: determining the general interface of each business component through predefined unified export interface rules; and calling the general interface through the common components and system functions to obtain the various dependency information required for dependency injection. Component dependency parsing is performed on each dependency information until the dependency corresponding to each dependency information is obtained; When it is detected that a system component calls the interface of a 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 dependency injection process of the component. Specifically, when a system component is detected calling an interface of a business component, the dependency items corresponding to the dependency information are injected into the instance of the business component through a dependency injection mechanism to complete the dependency injection process of the component, including: When a system component is detected calling a business component interface, the dependency corresponding to the business component interface is searched in the dependency injection system. Obtain the instance type name and instance object that the business component depends on from the dependencies; The dependency injection process of the component is completed by injecting the instance type name and the instance object into the instance of the business component through the dependency injection system and the public interface corresponding to the public component.
2. The method according to claim 1, characterized in that, When a business requirement is received, the software components are abstracted based on the business requirement to obtain common components, including: When a business requirement is received, the business components that ensure the basic functions of the software and the components that provide public services during software operation are identified based on the business requirement. Business components that ensure the basic functions of the software, as well as components that provide public services during software operation, are identified as public components.
3. The method according to claim 1, characterized in that, The step of parsing the component dependencies of each dependency information until the dependency corresponding to each dependency information is obtained includes: For each dependency information, the internal data structure of the dependency information is traversed through the dependency injection system to obtain the target component; the target component is a component of the dependency instance. Obtain the handle of the target component and the name of its dependency instance, and cache the handle and the name of its dependency instance in a temporary data structure; 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.
4. The method according to claim 1, characterized in that, Also includes: When the dependencies corresponding to each dependency information are obtained, it is determined whether the corresponding dependency of each dependency information generates its own instance. If so, store the dependencies for generating the instance in the data structure; If not, determine the generic interface for the dependency that has not been instantiated, generate an instance of the dependency through the generic interface, and store the dependency with the generated instance in the data structure.
5. A component dependency injection device, characterized in that, The device includes: A business abstraction unit is used to abstract the software components according to the business requirements when a business requirement is received, so as to obtain common components; wherein, the common components consist of business components that guarantee the basic functions of the software and components that provide common services during software operation; The acquisition unit is used to obtain the various dependency information required for dependency injection by calling the general interface through the public component; The parsing unit is 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 the system component calls the interface of the business component, so as to complete the dependency injection process of the component. The acquisition unit includes: The second determination module is used to determine the common interface of each business component through predefined unified export interface rules; The first acquisition module is used to obtain the various dependency information required for dependency injection by calling the general interface through the public components and system functions; The injection unit includes: The lookup module is used to search for the dependencies corresponding to the business component interfaces in the dependency injection system when a system component calls a business component interface. The third acquisition module is used to obtain the instance type name and instance object that the business component depends on from the dependencies; The injection module is used to inject the instance type name and the instance object into the instance of the business component through the dependency injection system and the public interface corresponding to the public component, so as to complete the dependency injection process of the component.
6. The apparatus according to claim 5, characterized in that, The business abstraction unit yields common components, including: The identification module is used to identify, upon receiving a business requirement, the business components that ensure the basic functions of the software and the components that provide public services during software operation, based on the business requirement. The first determination module is used to determine the business components that guarantee the basic functions of the software and the components that provide public services during the software operation as public components.
7. A storage medium, characterized in that, The storage medium includes stored instructions, wherein, when the instructions are executed, the device in which the storage medium resides is controlled to perform the component dependency injection method as described in any one of claims 1 to 4.
8. An electronic device, characterized in that, It includes memory, and one or more instructions, wherein one or more instructions are stored in memory and configured to be executed by one or more processors as described in any one of claims 1 to 4.
Citation Information
Patent Citations
Component development method and device, electronic equipment and storage medium
CN116149639A
Software project dependency relationship construction method, device and equipment and readable storage medium
CN117785214A