File read-write method and device based on dependency injection, equipment and medium
By detecting file read/write conditions on the framework side and using dependency injection to decouple business logic from underlying file read/write operations, the problem of high coupling between file read/write operations and business logic is solved, improving system efficiency and security.
Patent Information
- Application Number
- CN202410642525.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-22
- Publication Date
- 2025-11-25
AI Technical Summary
In existing technologies, file read and write operations are highly coupled with business logic, resulting in poor code maintainability, low system stability, and insufficient data security.
By detecting file read/write conditions on the framework side, loading data to be read/written using a dependency injection mechanism, and determining the target path based on the pre-injected dependency injection business modules, the decoupling of business logic from underlying file read/write is achieved.
This decouples business logic from underlying file reading and writing, improving system efficiency and security, and ensuring system stability and maintainability.
Smart Images

Figure CN121008739A_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to the field of data processing technology, and in particular to a method, apparatus, device, and medium for reading and writing files based on dependency injection. Background Technology
[0002] In system design and development, file reading and writing (also known as file I / O) are common and important operations. Whether it's simple data recording or complex data processing, it may be necessary to read and write files.
[0003] Currently, file read and write operations are typically performed by calling operating system APIs (Application Programming Interfaces) or using third-party libraries during the process of handling user requests, data verification, business rule implementation, data persistence, and other modules directly related to file read and write operations on the business side.
[0004] This approach, which integrates business logic with underlying file read / write operations on the same side, results in a high degree of coupling between the two, leading to complex dependencies between the code and impacting maintainability and reusability. This, in turn, reduces system stability and efficiency. Furthermore, this method directly accesses the system's underlying storage resources during file read / write operations, posing a risk of data security vulnerabilities. Summary of the Invention
[0005] This disclosure provides a method, apparatus, device, and medium for reading and writing files based on dependency injection, so as to achieve the effects of ensuring system security and stability and improving system efficiency.
[0006] In a first aspect, embodiments of this disclosure provide a file read / write method based on dependency injection, which is applied to a framework and includes:
[0007] When the file read / write conditions are met, the data read function is invoked to load the data to be read / written based on the implementation class corresponding to the data read function;
[0008] Based on the read / write path corresponding to at least one business module pre-injected with dependency injection and the target business module corresponding to the data to be read / written, determine the target path corresponding to the data to be read / written.
[0009] The data to be read or written is written to the target disk or read from the target disk based on the target path.
[0010] Secondly, embodiments of this disclosure also provide a file read / write device based on dependency injection, the device being configured on the framework side, the device comprising:
[0011] The function call module is used to call the data reading function when the file read / write conditions are detected, so as to load the data to be read / written based on the implementation class corresponding to the data reading function;
[0012] The path determination module is used to determine the target path corresponding to the data to be read and written based on the read and write path corresponding to at least one business module pre-injected and the target business module corresponding to the data to be read and written.
[0013] The data read / write module is used to write the data to be read / written to the target disk or read it from the target disk based on the target path.
[0014] Thirdly, embodiments of this disclosure also provide an electronic device, the electronic device comprising:
[0015] One or more processors;
[0016] Storage device for storing one or more programs.
[0017] When the one or more programs are executed by the one or more processors, the one or more processors implement the file read / write method based on dependency injection as described in any of the embodiments of this disclosure.
[0018] Fourthly, embodiments of this disclosure also provide a storage medium containing computer-executable instructions, which, when executed by a computer processor, are used to perform a file read / write method based on dependency injection as described in any of the embodiments of this disclosure.
[0019] Fifthly, embodiments of the present invention also provide a computer program product, including a computer program that, when executed by a processor, implements a file read / write method based on dependency injection as described in any of the embodiments of the present invention.
[0020] The technical solution of this disclosure, when the framework detects that the file read / write conditions are met, calls a data reading function to load the data to be read / written based on the implementation class corresponding to the data reading function; based on the read / write path corresponding to at least one business module pre-injected with dependencies and the target business module corresponding to the data to be read / written, determines the target path corresponding to the data to be read / written; and then, writes or reads the data to be read / written to the target disk based on the target path. This decouples the business logic from the underlying file read / write, enabling the business side to handle complex file read / write business logic without directly involving the underlying file read / write operations, and enabling the framework side to handle complex file read / write operations. This improves system efficiency while ensuring system security and stability. Attached Figure Description
[0021] The above and other features, advantages, and aspects of the embodiments of this disclosure will become more apparent from the accompanying drawings and the following detailed description. Throughout the drawings, the same or similar reference numerals denote the same or similar elements. It should be understood that the drawings are schematic, and the originals and elements are not necessarily drawn to scale.
[0022] Figure 1 This is a schematic flowchart of a file reading and writing method based on dependency injection provided in an embodiment of this disclosure;
[0023] Figure 2 This is a schematic flowchart of a file reading and writing method based on dependency injection provided in an embodiment of this disclosure;
[0024] Figure 3 This is a schematic flowchart of a file reading and writing method based on dependency injection provided in an embodiment of this disclosure;
[0025] Figure 4 This is a schematic flowchart of a file reading and writing method based on dependency injection provided in an embodiment of this disclosure;
[0026] Figure 5 This is a schematic flowchart of a file reading and writing method based on dependency injection provided in an embodiment of this disclosure;
[0027] Figure 6 This is a schematic flowchart of a file reading and writing method based on dependency injection provided in an embodiment of this disclosure;
[0028] Figure 7 This is a schematic diagram of a file read / write device based on dependency injection provided in an embodiment of this disclosure;
[0029] Figure 8 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this disclosure. Detailed Implementation
[0030] Embodiments of this disclosure will now be described in more detail with reference to the accompanying drawings. While some embodiments of this disclosure are shown in the drawings, it should be understood that this disclosure can be implemented in various forms and should not be construed as limited to the embodiments set forth herein. Rather, these embodiments are provided to provide a more thorough and complete understanding of this disclosure. It should be understood that the accompanying drawings and embodiments of this disclosure are for illustrative purposes only and are not intended to limit the scope of protection of this disclosure.
[0031] It should be understood that the steps described in the method embodiments of this disclosure may be performed in different orders and / or in parallel. Furthermore, the method embodiments may include additional steps and / or omit the steps shown. The scope of this disclosure is not limited in this respect.
[0032] The term "comprising" and its variations as used herein are open-ended inclusions, meaning "including but not limited to". The term "based on" means "at least partially based on". The term "one embodiment" means "at least one embodiment"; the term "another embodiment" means "at least one additional embodiment"; the term "some embodiments" means "at least some embodiments". Definitions of other terms will be given in the description below.
[0033] It should be noted that the concepts of "first" and "second" mentioned in this disclosure are used only to distinguish different devices, modules or units, and are not used to limit the order of functions performed by these devices, modules or units or their interdependencies.
[0034] It should be noted that the terms "a" and "a plurality of" used in this disclosure are illustrative rather than restrictive, and those skilled in the art should understand that, unless otherwise expressly indicated in the context, they should be understood as "one or more".
[0035] The names of messages or information exchanged between multiple devices in the embodiments of this disclosure are for illustrative purposes only and are not intended to limit the scope of such messages or information.
[0036] It is understood that before using the technical solutions disclosed in the various embodiments of this disclosure, users should be informed of the types, scope of use, and usage scenarios of the personal information involved in this disclosure in an appropriate manner in accordance with relevant laws and regulations, and user authorization should be obtained.
[0037] For example, upon receiving a user's active request, a prompt message is sent to the user to explicitly inform them that the requested operation will require the acquisition and use of the user's personal information. This allows the user to independently choose whether to provide personal information to the software or hardware, such as the electronic device, application, server, or storage medium performing the operations of this disclosed technical solution, based on the prompt message.
[0038] As an optional but non-limiting implementation, in response to a user's active request, sending a prompt message to the user can be done via a pop-up window, where the prompt message can be presented in text format. Furthermore, the pop-up window can also include a selection control allowing the user to choose "agree" or "disagree" to provide personal information to the electronic device.
[0039] It is understood that the above notification and user authorization process are merely illustrative and do not constitute a limitation on the implementation of this disclosure. Other methods that comply with relevant laws and regulations may also be applied to the implementation of this disclosure.
[0040] It is understood that the data involved in this technical solution (including but not limited to the data itself, the acquisition or use of the data) shall comply with the requirements of relevant laws, regulations and related provisions.
[0041] Before introducing the technical solutions provided by the embodiments of this disclosure, the application scenarios can be illustrated by example. The technical solutions of the embodiments of this disclosure can be applied to any scenario that requires reading and writing files. For example, when developing a system, reading and writing operations on underlying files are usually involved. These reading and writing operations on underlying files can be implemented based on the technical solutions of the embodiments of this disclosure.
[0042] Figure 1 This is a schematic flowchart of a file reading and writing method based on dependency injection provided in this embodiment. This embodiment is applicable to the scenario of reading and writing files. The method can be implemented by a file reading and writing device based on dependency injection. The file reading and writing device based on dependency injection can be deployed in a computer device. Optionally, the computer device can be a PC or a mobile terminal, etc.
[0043] like Figure 1 As shown, the method includes:
[0044] S110. When the file read / write conditions are met, the data read function is invoked to load the data to be read / written based on the implementation class corresponding to the data read function.
[0045] Here, file read / write conditions can be understood as the conditions under which file read / write operations should be performed. A data read function can be a function or method used to read data; the data read function does not contain the specific implementation of the function. The implementation class encapsulates the logic for loading data.
[0046] In this embodiment, file read / write conditions can be pre-configured. Optionally, file read / write conditions can include having access permissions to the file, the file existing in a specified location, the file size not exceeding a set range, sufficient disk space for reading or writing the file, the file being the expected file type, the file being in a healthy state, or triggering a file read / write control, etc. When the framework detects that the file read / write conditions are met, it can call a data reading function, then obtain the corresponding implementation class through the data reading function, and load the data to be read / written through the implementation class to obtain the data to be read / written.
[0047] For example, the business logic can create a class to encapsulate the data reading logic; this class is the implementation class. The framework then loads the data by calling the data reading function to obtain its implementation class.
[0048] S120. Based on the read / write path corresponding to at least one business module pre-injected with dependency injection and the target business module corresponding to the data to be read / written, determine the target path corresponding to the data to be read / written.
[0049] Here, a business module can refer to a module used to implement business functions. For example, a business module can be a module that defines how data is produced and how data is consumed. The target path can be the location on the target disk to be written to, or the location within the target disk.
[0050] In this embodiment, dependency injection can be used to inject at least one business module into the framework. The framework can then select a target business module from the at least one dependency-injected business module that corresponds to the data to be read or written. For example, the dependency-injected business module may contain the filename and relative path of the file. The framework can find the filename corresponding to the data to be read or written from the business modules, and the found business module can be used as the target business module. Furthermore, the relative path corresponding to the target business module can be used as the target path corresponding to the data to be read or written.
[0051] For example, see Figure 2 To illustrate, let's take writing data as an example: The business side generates the binary result of the data (dataBuffer) and the data's location on the disk (filePath) through the business engineering. The business side then provides the binary result and the data's location on the disk to the framework side. The framework side uses a relative path to perform a write operation on the binary result of the data (i.e., the data to be read / written) to write the data to the disk.
[0052] To illustrate further, let's take reading data as an example: The business side generates data and provides it to the framework side via the relative path on the disk. The framework side uses the relative path (filePath) to load the file from the disk to obtain binary data (dataBuffer), which is the data to be read and written. This binary data is then given to the business side so that the business can consume the data to be read and written.
[0053] S130. Write the data to be read / written to the target disk or read it from the target disk based on the target path.
[0054] In this embodiment, if writing data to be read / written is required, the data can be written to the target path on the target disk. If reading data to be read / written is required, the data can be read from the target path on the target disk.
[0055] To ensure orderly file reading and writing and maintain system stability, the order in which data is written to or read from the target disk can be controlled based on a predefined control chain.
[0056] In this embodiment, the framework can use a control chain to control the order in which data is read and written. For example, the control chain can be a Promise chain, which connects multiple asynchronous read and write operations together to control the execution order of asynchronous read and write operations.
[0057] The advantage of this setup is that by using a control chain to control the execution order of the entire file I / O operation, it can improve the flexibility of controlling the execution order of read and write operations, avoid timing and stability issues introduced by asynchronous read and write, effectively avoid concurrency control issues, and at the same time, provide an error handling mechanism, thereby ensuring high performance in the face of concurrent requests and cross loads.
[0058] The technical solution of this disclosure, when the framework detects that the file read / write conditions are met, calls a data reading function to load the data to be read / written based on the implementation class corresponding to the data reading function; based on the read / write path corresponding to at least one business module pre-injected with dependencies and the target business module corresponding to the data to be read / written, determines the target path corresponding to the data to be read / written; and then, writes or reads the data to be read / written to the target disk based on the target path. This decouples the business logic from the underlying file read / write, enabling the business side to handle complex file read / write business logic without directly involving the underlying file read / write operations, and enabling the framework side to handle complex file read / write operations. This improves system efficiency while ensuring system security and stability.
[0059] Figure 3 This is a flowchart illustrating a file reading and writing method based on dependency injection provided in this embodiment. Based on the aforementioned embodiment, at least one business module integrated in the business project can be received in advance. Then, the at least one business module is instantiated to obtain an abstract class result corresponding to the at least one business module. Furthermore, the method classes in the at least one business module are injected into the IOC container based on dependency injection. Based on the data injected into the IOC container, the target path corresponding to the target business module is determined. For a detailed description of the specific implementation, please refer to the detailed description of this embodiment. Technical features that are the same as or similar to those in the aforementioned embodiment will not be repeated here.
[0060] like Figure 3 As shown, the method in this embodiment may specifically include:
[0061] S210, Receive at least one service module integrated in the service engineering.
[0062] Business engineering can be understood as the project engineering of developing a system. Different business modules integrated into business engineering can be used to implement different business functions or behaviors within the business engineering framework.
[0063] S220. Instantiate at least one business module to obtain an abstract class result corresponding to at least one business module.
[0064] The abstract class result corresponds to the description information of the business module, which includes, but is not limited to, the implementation code of the business module, the relative path of the module file, and the data buffer.
[0065] In this embodiment, the business side provides at least one business module integrated in the business engineering. The framework side instantiates each business module to obtain a concrete instance of each business module. The framework side uses keywords to declare the implementation of concrete instances in an abstract class, obtaining an abstract class result, so that the abstract class result can provide concrete implementations of all methods defined in the business module, allowing the framework side to hold each business module of the business side, that is, to hold the concrete implementation of the business function.
[0066] For example, see [link to previous article] Figure 2 The framework creates an IProject object, and the business side defines custom classes that implement each method in IProject, such as the load and save methods. The business side's business projects inherit from and extend the framework's objects, and the business modules within these projects implement business functionalities. Business modules can be instantiated, and their properties and behaviors can be defined through these instantiated IProject objects to obtain abstract class results. The framework can then use these business modules by calling the IProject object.
[0067] S230. Inject at least one method class from a business module into the IOC container using dependency injection, and determine the target path corresponding to the target business module based on the data injected into the IOC container.
[0068] Among them, the IOC (Inversion of Control) container refers to the container with inversion of control.
[0069] It's important to note that methods are defined within a class and describe the behavior an object can perform. A method can be a function or operation associated with an object. When an object of a class is created, that object will contain references to all the methods defined in the class. An object can also refer to the instantiation result of a business module.
[0070] In this embodiment, dependency injection can be used to inject the method classes of each business module into the IOC container, that is, to inject the business modules on the business side into the IOC container. This allows the framework to obtain the target path corresponding to the target business module through the data injected into the IOC container when reading and writing data, thereby obtaining the target path corresponding to the data to be read and written.
[0071] To ensure that file reading meets the read requirements of the business side, when injecting method classes from at least one business module into the IOC container using dependency injection, basic information can also be configured for these method classes. This basic information includes the relative paths of the data generated or consumed by the business module on the disk, allowing the target path to be determined based on these relative paths. The technical solution provided in this embodiment, by defining basic information within business modules on the framework side, enables the framework side to use the business-side-defined basic information.
[0072] The technical solution of this disclosure receives at least one business module integrated in the business project, then instantiates the at least one business module to obtain an abstract class corresponding to the at least one business module. The method classes in the at least one business module are injected into the IOC container using dependency injection. By utilizing dependency injection, business logic and underlying file read / write operations are decoupled. This allows the business side to customize read / write behavior, while the framework side can use predefined business modules to uniformly manage the read / write behavior of the business side, ensuring the security and efficiency of data transmission from the business side to the underlying framework. Simultaneously, by decoupling business logic and underlying file read / write operations, code maintainability and extensibility are improved. The business side can handle complex file read / write business logic without directly involving underlying file read / write operations, while the framework side can handle complex file read / write operations through the business modules of the business side, achieving the effect of ensuring system security and stability.
[0073] Figure 4 This is a flowchart illustrating a file read / write method based on dependency injection provided in this embodiment. Based on the foregoing embodiments, S110 is further refined. For specific implementation details, please refer to the detailed description of the embodiments in this disclosure. Technical terms that are the same as or corresponding to those in the above embodiments will not be repeated in this embodiment.
[0074] like Figure 4 As shown, the method in this embodiment may specifically include:
[0075] S310. When a save or load of an editor project file is detected, determine that the file read / write conditions are met.
[0076] Here, "editor" can refer to an integrated development environment (IDE). A project can be used to store all the files required for the project, such as source code files, header files, resource files, configuration files, etc.
[0077] In this embodiment, a file listening event can be used to monitor whether the editor project file is saved or loaded; or, an interface or plugin mechanism can be used to detect whether there are events or callbacks related to file saving or loading. If they exist, it is considered that the editor project file has been saved or loaded.
[0078] S320. Call the data reading function corresponding to the data to be read / written in the result of the abstract class, and load the data to be read / written based on the implementation class of the data reading function.
[0079] For example, see Figure 5 To illustrate, let's take writing data as an example: When the project file is saved in the editor, the framework can call the data reading function generate{} in the abstract class result. The implementation class (which is implemented by the business side) can be obtained through the data reading function. For example, the implementation class can be generate{read data from memory and return}. The data returned by the business side is the data to be read and written, and the data to be read and written is written to the target disk.
[0080] S330. Based on the read / write path corresponding to at least one business module pre-injected with dependency injection and the target business module corresponding to the data to be read / written, determine the target path corresponding to the data to be read / written.
[0081] S340. Write the data to be read / written to the target disk or read it from the target disk based on the target path.
[0082] The technical solution of this disclosure, when detecting the saving or loading of the editor project file and determining that the file read / write conditions are met, calls the data reading function corresponding to the data to be read / written in the abstract class result, and loads the data to be read / written based on the implementation class of the data reading function. After the framework layer loads the data to be read / written on the business side, it is transformed into a specific file read / write operation and executed. This method ensures that while maintaining the decoupling between business logic and file read / write operations, it can realize arbitrarily complex file read / write operations, thus ensuring the security and stability of system read / write.
[0083] Figure 6 This is a flowchart illustrating a file read / write method based on dependency injection provided in this embodiment. Based on the foregoing embodiments, S120 is further refined. For specific implementation details, please refer to the detailed description of the embodiments in this disclosure. Technical terms that are the same as or corresponding to those in the above embodiments will not be repeated in this embodiment.
[0084] like Figure 6 As shown, the method in this embodiment may specifically include:
[0085] S410. When the file read / write conditions are met, the data read function is invoked to load the data to be read / written based on the implementation class corresponding to the data read function.
[0086] S420, retrieves the target object for saving or loading data.
[0087] The target object can refer to the object used to process read and write data, and is responsible for the association of read and write operations on the entire framework side. For example, when a program needs to access a file, it interacts with the target object instead of directly interacting with the file system to ensure system performance and efficiency.
[0088] S430. Based on the target object, retrieve the data corresponding to at least one business module pre-injected based on dependency injection from the IOC container, and determine the target path of the target business module corresponding to the data to be read and written.
[0089] In this embodiment, basic information corresponding to at least one business module for dependency injection can be obtained from the IOC container through the target object. The target business module is determined from the business modules based on the basic information and the filename of the data to be read / written. The relative path of the data generated or consumed by the business module on the disk is obtained from the basic information of the target business module. The relative path can be used as the target path of the target business module corresponding to the data to be read / written, so that the data to be read / written can be written to the target disk or read from the target disk through the target path.
[0090] For example, see [link to previous article] Figure 5 By calling the write method through the target object, the method in the business module of dependency injection in the IOC container and the relative path to write the data to be read and written to the disk are obtained. The relative path is used as the target path, and the data to be read and written is executed through the target path and the data to be read and written.
[0091] S440: Write the data to be read / written to the target disk or read it from the target disk based on the target path.
[0092] The technical solution of this disclosure embodiment retrieves the target object of the saved data or loaded data, and then, based on the target object, obtains the data corresponding to at least one business module pre-injected based on dependency injection from the IOC container, determines the target path of the target business module corresponding to the data to be read and written, so that the data to be read and written is written to the target disk or read from the target disk through the target path, thereby achieving decoupling of business logic and underlying file reading and writing, while ensuring that file operations do not affect the security and stability of the system, thus achieving the effect of ensuring system security and stability.
[0093] Figure 7This is a schematic diagram of a file read / write device based on dependency injection provided in an embodiment of this disclosure. The device is configured on the frame side, as shown below. Figure 7 As shown, the device includes: a function call module 510, a path determination module 520, and a data read / write module 530.
[0094] The function retrieval module 510 is used to retrieve a data reading function when the file read / write conditions are met, so as to load the data to be read / written based on the implementation class corresponding to the data reading function; the path determination module 520 is used to determine the target path corresponding to the data to be read / written based on the read / write path corresponding to at least one business module pre-injected with dependency injection and the target business module corresponding to the data to be read / written; the data read / write module 530 is used to write the data to be read / written to the target disk or read it from the target disk based on the target path.
[0095] Based on the above technical solution, the device further includes a dependency injection module, which includes: a business module receiving unit for receiving at least one business module integrated in the business project; an instantiation unit for instantiating the at least one business module to obtain an abstract class result corresponding to the at least one business module, wherein the abstract class result corresponds to the description information of the business module; and a dependency injection unit for injecting the method classes in the at least one business module into the IOC container based on dependency injection, so as to determine the target path corresponding to the target business module based on the data injected in the IOC container.
[0096] Based on the above technical solutions, the device further includes: a basic information configuration unit, used to configure basic information for the method class in the at least one business module, wherein the basic information includes the relative path of the data generated or consumed by the business module on the disk, so as to determine the target path based on the relative path.
[0097] Based on the above technical solutions, the function retrieval module 510 includes: a detection unit, used to determine that the file read / write conditions are met when the editor project file is saved or loaded; and a function retrieval unit, used to retrieve the data reading function corresponding to the data to be read / written from the abstract class result, and load the data to be read / written based on the implementation class of the data reading function.
[0098] Based on the above technical solutions, the path determination module 520 includes: a target object retrieval unit, used to retrieve the target object for saving or loading data; and a path determination unit, used to determine the target path of the target business module corresponding to the data to be read and written from the data corresponding to at least one business module pre-injected based on dependency injection obtained from the IOC container based on the target object.
[0099] Based on the above technical solutions, the device further includes: an execution sequence control unit, used to control the order in which data to be read or written is written to the target disk or read from the target disk based on a predefined control chain.
[0100] The technical solution of this disclosure, when the framework detects that the file read / write conditions are met, calls a data reading function to load the data to be read / written based on the implementation class corresponding to the data reading function; based on the read / write path corresponding to at least one business module pre-injected with dependencies and the target business module corresponding to the data to be read / written, determines the target path corresponding to the data to be read / written; and then, writes or reads the data to be read / written to the target disk based on the target path. This decouples the business logic from the underlying file read / write, enabling the business side to handle complex file read / write business logic without directly involving the underlying file read / write operations, and enabling the framework side to handle complex file read / write operations. This improves system efficiency while ensuring system security and stability.
[0101] The file read / write device based on dependency injection provided in this disclosure can execute the file read / write method based on dependency injection provided in any embodiment of this disclosure, and has the corresponding functional modules and beneficial effects of the execution method.
[0102] It is worth noting that the various units and functional modules included in the above-mentioned device are only divided according to functional logic, but are not limited to the above division, as long as the corresponding functions can be realized; in addition, the specific names of each functional unit are only for easy differentiation and are not used to limit the protection scope of the embodiments of this disclosure.
[0103] Figure 8 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this disclosure. Reference is made below. Figure 8 It illustrates an electronic device suitable for implementing embodiments of the present disclosure (e.g., Figure 8The diagram below shows the structure of the terminal device or server 600. The terminal device in this embodiment may include, but is not limited to, mobile terminals such as mobile phones, laptops, digital broadcast receivers, PDAs (personal digital assistants), PADs (tablet computers), PMPs (portable multimedia players), and vehicle terminals (e.g., vehicle navigation terminals), as well as fixed terminals such as digital TVs and desktop computers. Figure 8 The electronic device shown is merely an example and should not be construed as limiting the functionality and scope of the embodiments disclosed herein.
[0104] like Figure 8 As shown, electronic device 600 may include a processing unit (e.g., a central processing unit, a graphics processing unit, etc.) 601, which can perform various appropriate actions and processes according to a program stored in read-only memory (ROM) 602 or a program loaded from storage device 608 into random access memory (RAM) 603. The RAM 603 also stores various programs and data required for the operation of electronic device 600. The processing unit 601, ROM 602, and RAM 603 are interconnected via bus 604. An edit / output (I / O) interface 605 is also connected to bus 604.
[0105] Typically, the following devices can be connected to I / O interface 605: input devices 606 including, for example, touchscreens, touchpads, keyboards, mice, cameras, microphones, accelerometers, gyroscopes, etc.; output devices 607 including, for example, liquid crystal displays (LCDs), speakers, vibrators, etc.; storage devices 608 including, for example, magnetic tapes, hard disks, etc.; and communication devices 609. Communication device 609 allows electronic device 600 to communicate wirelessly or wiredly with other devices to exchange data. Although Figure 8 An electronic device 600 with various devices is shown; however, it should be understood that it is not required to implement or possess all of the devices shown. More or fewer devices may be implemented or possessed alternatively.
[0106] In particular, according to embodiments of this disclosure, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments of this disclosure include a computer program product comprising a computer program carried on a non-transitory computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via a communication device 609, or installed from a storage device 608, or installed from a ROM 602. When the computer program is executed by the processing device 601, it performs the functions defined in the methods of embodiments of this disclosure.
[0107] The names of messages or information exchanged between multiple devices in the embodiments of this disclosure are for illustrative purposes only and are not intended to limit the scope of such messages or information.
[0108] The electronic device provided in this embodiment and the file reading and writing method based on dependency injection provided in the above embodiments belong to the same inventive concept. Technical details not described in detail in this embodiment can be found in the above embodiments, and this embodiment has the same beneficial effects as the above embodiments.
[0109] This disclosure provides a computer storage medium storing a computer program that, when executed by a processor, implements the file read / write method based on dependency injection provided in the above embodiments.
[0110] It should be noted that the computer-readable medium described in this disclosure can be a computer-readable signal medium or a computer-readable storage medium, or any combination thereof. A computer-readable storage medium can be, for example,—but not limited to—an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of a computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In this disclosure, a computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in connection with an instruction execution system, apparatus, or device. In this disclosure, a computer-readable signal medium can include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code. Such propagated data signals can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A computer-readable signal medium can be any computer-readable medium other than a computer-readable storage medium, which can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium can be transmitted using any suitable medium, including but not limited to: wires, optical fibers, RF (radio frequency), etc., or any suitable combination thereof.
[0111] In some implementations, clients and servers can communicate using any currently known or future-developed network protocol such as HTTP (Hypertext Transfer Protocol) and can interconnect with digital data communication (e.g., communication networks) of any form or medium. Examples of communication networks include local area networks (“LANs”), wide area networks (“WANs”), the Internet (e.g., the Internet of Things), and peer-to-peer networks (e.g., ad hoc peer-to-peer networks), as well as any currently known or future-developed networks.
[0112] The aforementioned computer-readable medium may be included in the aforementioned electronic device; or it may exist independently and not assembled into the electronic device.
[0113] The aforementioned computer-readable medium carries one or more programs that, when executed by the electronic device, cause the electronic device to:
[0114] When the file read / write conditions are met, the data read function is invoked to load the data to be read / written based on the implementation class corresponding to the data read function;
[0115] Based on the read / write path corresponding to at least one business module pre-injected with dependency injection and the target business module corresponding to the data to be read / written, determine the target path corresponding to the data to be read / written.
[0116] The data to be read or written is written to the target disk or read from the target disk based on the target path.
[0117] Computer program code for performing the operations of this disclosure can be written in one or more programming languages or a combination thereof, including but not limited to object-oriented programming languages such as Java, Smalltalk, and C++, as well as conventional procedural programming languages such as the "C" language or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving remote computers, the remote computer can be connected to the user's computer via any type of network—including a local area network (LAN) or a wide area network (WAN)—or can be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0118] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of this disclosure. In this regard, each block in a flowchart or block diagram may represent a functional module, program segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.
[0119] This disclosure also provides a computer program product, including a computer program that, when executed by a processor, implements a file read / write method based on dependency injection as provided in any embodiment of this disclosure.
[0120] In implementing the computer program product, computer program code for performing the operations of this invention can be written in one or more programming languages or a combination thereof. Programming languages include object-oriented programming languages such as Java, Smalltalk, and C++, as well as conventional procedural programming languages such as C or similar languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving remote computers, the remote computer can be connected to the user's computer via any type of network—including a local area network (LAN) or a wide area network (WAN)—or can be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0121] According to one or more embodiments of this disclosure, [Example 1] provides a file read / write method based on dependency injection, which is applied to the framework side and includes:
[0122] When the file read / write conditions are met, the data read function is invoked to load the data to be read / written based on the implementation class corresponding to the data read function;
[0123] Based on the read / write path corresponding to at least one business module pre-injected with dependency injection and the target business module corresponding to the data to be read / written, determine the target path corresponding to the data to be read / written.
[0124] The data to be read or written is written to the target disk or read from the target disk based on the target path.
[0125] According to one or more embodiments of this disclosure, [Example 2] provides a file read / write method based on dependency injection, the method further comprising:
[0126] Receive at least one business module integrated in the business engineering;
[0127] The at least one business module is instantiated to obtain an abstract class result corresponding to the at least one business module, wherein the abstract class result corresponds to the description information of the business module; and,
[0128] The method classes in the at least one business module are injected into the IOC container using dependency injection, so as to determine the target path corresponding to the target business module based on the data injected into the IOC container.
[0129] According to one or more embodiments of this disclosure, [Example 3] provides a file read / write method based on dependency injection, the method further comprising:
[0130] Configure basic information for method classes in at least one business module, wherein the basic information includes the relative path of the data generated or consumed by the business module on the disk, so as to determine the target path based on the relative path.
[0131] According to one or more embodiments of this disclosure, [Example 4] provides a file read / write method based on dependency injection, the method further comprising:
[0132] When the save or load of the editor project file is detected, it is determined that the file read / write conditions are met;
[0133] The data reading function corresponding to the data to be read and written is invoked from the abstract class result, and the data to be read and written is loaded based on the implementation class of the data reading function.
[0134] According to one or more embodiments of this disclosure, [Example 5] provides a file read / write method based on dependency injection, the method further comprising:
[0135] The target object for retrieving saved or loaded data;
[0136] Based on the target object, the target path of the target business module corresponding to the data to be read and written is determined from the data corresponding to at least one business module pre-injected based on dependency injection obtained from the IOC container.
[0137] According to one or more embodiments of this disclosure, [Example Six] provides a file read / write method based on dependency injection, the method further comprising:
[0138] The order in which data to be read or written is controlled based on a predefined control chain.
[0139] According to one or more embodiments of this disclosure, [Example Seven] provides a file read / write device based on dependency injection, the device being configured on the frame side, the device comprising:
[0140] The function call module is used to call the data reading function when the file read / write conditions are detected, so as to load the data to be read / written based on the implementation class corresponding to the data reading function;
[0141] The path determination module is used to determine the target path corresponding to the data to be read and written based on the read and write path corresponding to at least one business module pre-injected and the target business module corresponding to the data to be read and written.
[0142] The data read / write module is used to write the data to be read / written to the target disk or read it from the target disk based on the target path.
[0143] The above description is merely a preferred embodiment of this disclosure and an explanation of the technical principles employed. Those skilled in the art should understand that the scope of this disclosure is not limited to technical solutions formed by specific combinations of the above-described technical features, but should also cover other technical solutions formed by arbitrary combinations of the above-described technical features or their equivalents without departing from the above-described concept. For example, technical solutions formed by substituting the above features with (but not limited to) technical features disclosed in this disclosure that have similar functions.
[0144] Furthermore, while the operations are described in a specific order, this should not be construed as requiring these operations to be performed in the specific order shown or in a sequential order. In certain environments, multitasking and parallel processing may be advantageous. Similarly, while several specific implementation details are included in the above discussion, these should not be construed as limiting the scope of this disclosure. Certain features described in the context of individual embodiments may also be implemented in combination in a single embodiment. Conversely, various features described in the context of a single embodiment may also be implemented individually or in any suitable sub-combination in multiple embodiments.
[0145] Although the subject matter has been described using language specific to structural features and / or methodological logic, it should be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or actions described above. Rather, the specific features and actions described above are merely illustrative examples of implementing the claims.
Claims
1. A file read / write method based on dependency injection, characterized in that, Applied to the frame side, the method includes: When the file read / write conditions are met, the data read function is invoked to load the data to be read / written based on the implementation class corresponding to the data read function; Based on the read / write path corresponding to at least one business module pre-injected with dependency injection and the target business module corresponding to the data to be read / written, determine the target path corresponding to the data to be read / written. The data to be read or written is written to the target disk or read from the target disk based on the target path.
2. The method according to claim 1, characterized in that, The method further includes: Receive at least one business module integrated in the business engineering; The at least one business module is instantiated to obtain an abstract class result corresponding to the at least one business module, wherein the abstract class result corresponds to the description information of the business module; and, The method classes in at least one business module are injected into the IOC container using dependency injection, so as to determine the target path corresponding to the target business module based on the data injected into the IOC container.
3. The method according to claim 2, characterized in that, When injecting the method classes in the at least one business module into the IOC container using dependency injection, the method further includes: Configure basic information for method classes in at least one business module, wherein the basic information includes the relative path of the data generated or consumed by the business module on the disk, so as to determine the target path based on the relative path.
4. The method according to claim 1, characterized in that, The step of calling a data reading function when the file read / write conditions are met, and loading the data to be read / written based on the implementation class corresponding to the data reading function, includes: When the save or load of the editor project file is detected, it is determined that the file read / write conditions are met; The data reading function corresponding to the data to be read and written is invoked from the abstract class result, and the data to be read and written is loaded based on the implementation class of the data reading function.
5. The method according to claim 1, characterized in that, The determination of the target path corresponding to the data to be read and written, based on the read / write path corresponding to at least one business module obtained through pre-dependency injection and the target business module corresponding to the data to be read and written, includes: The target object for retrieving saved or loaded data; Based on the target object, the target path of the target business module corresponding to the data to be read and written is determined from the data corresponding to at least one business module pre-injected based on dependency injection obtained from the IOC container.
6. The method according to claim 1, characterized in that, Also includes: The order in which data to be read or written is controlled based on a predefined control chain.
7. A file read / write device based on dependency injection, characterized in that, The device, configured on the frame side, includes: The function call module is used to call the data reading function when the file read / write conditions are detected, so as to load the data to be read / written based on the implementation class corresponding to the data reading function; The path determination module is used to determine the target path corresponding to the data to be read and written based on the read and write path corresponding to at least one business module pre-injected and the target business module corresponding to the data to be read and written. The data read / write module is used to write the data to be read / written to the target disk or read it from the target disk based on the target path.
8. An electronic device, characterized in that, The electronic device includes: One or more processors; Storage device for storing one or more programs. When the one or more programs are executed by the one or more processors, the one or more processors implement the file read / write method based on dependency injection as described in any one of claims 1-6.
9. A storage medium containing computer-executable instructions, which, when executed by a computer processor, are used to perform a file read / write method based on dependency injection as described in any one of claims 1-6.
10. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by the processor, it implements the file read / write method based on dependency injection as described in any one of claims 1-6.
