CN106569835A - Realization method for inversion-of-control assembly based on go language - Google Patents
Realization method for inversion-of-control assembly based on go language Download PDFInfo
- Publication number
- CN106569835A CN106569835A CN201611000129.8A CN201611000129A CN106569835A CN 106569835 A CN106569835 A CN 106569835A CN 201611000129 A CN201611000129 A CN 201611000129A CN 106569835 A CN106569835 A CN 106569835A
- Authority
- CN
- China
- Prior art keywords
- function
- type
- interface
- providing
- language
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/20—Software design
- G06F8/24—Object-oriented
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/30—Creation or generation of source code
- G06F8/31—Programming languages or programming paradigms
- G06F8/315—Object-oriented languages
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/44—Arrangements for executing specific programs
- G06F9/445—Program loading or initiating
- G06F9/44521—Dynamic linking or loading; Link editing at or after load time, e.g. Java class loading
- G06F9/44526—Plug-ins; Add-ons
Landscapes
- Engineering & Computer Science (AREA)
- Software Systems (AREA)
- Theoretical Computer Science (AREA)
- General Engineering & Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Computing Systems (AREA)
- Stored Programmes (AREA)
Abstract
The invention discloses a realization method for an inversion-of-control assembly based on a go language. The realization method comprises the processes of providing an injection structural body firstly, wherein subsequent operations are realized based on the structural body; then providing a type mapping interface used for injecting parameters and obtaining the injected parameters in calling; providing an execution callee interface, wherein the interface provides a reflective calling function; providing an injecting interface; providing a function for setting a father node function; providing a function for reflecting a final living example; providing a function for generating an injector; providing a dynamic executing function for dynamically executing functions; and providing a function for performing injection on fields of the structural body. Compared with the prior art, the realization method for the inversion-of-control assembly based on the go language disclosed by the invention can solve the problem of overhigh complexity of the coupling relation of hard codes between assemblies according to the characteristics of the go language, so that re-compiling of codes is not required by a user; and loading of each assembly and service can be realized flexibly in the realization operation through configuration, so that high practicability is achieved.
Description
Technical field
The present invention relates to computer software technical field, specifically a kind of reality that inversion component is controlled based on go language
Existing method.
Background technology
Control reversion(Inversion of control)It is not the new terminology of computer software circle.Horse in 1988
Fourth. fowler proposes the concept of control reversion.The real world applications of control reversion can be divided into two classes:One kind is to rely on injection, according to
Bad injection is that the control reversion for configuring and generating example is obtained by context;Another kind is to rely on to search, and it is logical to rely on lookup
Cross and search the control reversion that screening washer generates example after screening.By control reversion, object when being created, by one
The outside entity of all objects in regulator control system, the reference of the object that it is relied on passes to it.It may also be said that rely on being noted
Enter in object.
Controlling the advantage of reversion is:Container can be according to the dependence between configuration schedules each components, drop during operation
The coupled relation of hard coded between low each component.
But in the prior art, the control of control reversion is difficult to hold, and high-level module depends on low level
Module, the realization under any one same module, it is impossible to seamless replacement, and by being affected larger when compiling, i.e., interface is located
Runtime environment affects larger to it, and the coupled relation complexity of hard coded is too high between each component, based on this, now provides one
Plant the implementation method based on go language control inversion component to solve the above problems.
The content of the invention
The technical assignment of the present invention is for above weak point, there is provided a kind of reality that inversion component is controlled based on go language
Existing method.
A kind of implementation method that inversion component is controlled based on go language, injected with self-defined constructed fuction by go language,
The mode of attribute injection arranges the container required for control reversion, and it implements process and is:
Injecting structure body is provided first, and subsequent operation is realized based on the structure;
Then Type mapping interface is provided, for injection parameter and when calling the parameter being injected into is obtained;
There is provided and perform callee interface, the interface provides a reflection call function;
There is provided grouting socket, there is provided a dependence is mapped to the function of a structure;
The function for arranging father node function is provided;
The function of the final example of reflection is provided, for returning the particular type of reflection;
The function for generating infusion appliance is provided, for returning a newly-generated infusion appliance example;
The function of Dynamic Execution function is provided, for Dynamic Execution function;
The function that the field to structure is injected is provided, for injecting to the field of structure, parameter is sensing bottom
Channel type is the pointer of structure.
Two member variables are included in the structure body:Values and parent, wherein values are used to preserve injection
Parameter, it is a key-value pair table Map.
Type mapping interface includes key-value pair table function, Set functions, Get functions, and wherein key-value pair table function is used to inject
Parameter, including Map and MapTo functions, Map functions are used for the Map Interface type used during storage running, and MapTo functions are used
The pointer of the Map Interface type used when storage running;Set functions are used to be inserted directly into the value of map type and mapping;
Get functions are used to obtain the value of mapping according to the type of mapping, obtain the parameter being injected into.
Arranging the function of father node function is used to arrange the father node of injection, when infusion appliance cannot find Type mapping,
By the function lookup, its father node whether there is the mapping of dependence to infusion appliance, if still do not had, returns a miscue
Information.
There is provided the function of the final example of reflection is used for the type that gets parms, and its incoming parameter is the pointer of interface type, its
Return type is the key assignmentses of key-value pair table in structure.
The function of infusion appliance is generated for initialisation structures body, and returns the pointer of a direction structure body, this return
Value pointer is packed by structure interface.
Compared to the prior art a kind of implementation method for controlling inversion component based on go language of the present invention, has with following
Beneficial effect:
A kind of implementation method that inversion component is controlled based on go language of the present invention, can be solved according to the characteristic of go language
The too high problem of the coupled relation complexity of hard coded between each component, so as to reach user code need not be recompilated,
Each component and service are flexibly loaded during by configuring and realize operation, it is practical, it is applied widely, with good
Application value.
Specific embodiment
With reference to specific embodiment, the invention will be further described.
The invention provides a kind of implementation method that inversion component is controlled based on go language, the method is based on the offer of go language
Interface, method, reflection characteristic of speech sounds and mechanism, self-defined constructed fuction injection, attribute injection by way of realize
Container required for control reversion, realizes operationally container according to the dependence between configuration schedules each components, drop
The coupled relation of hard coded between low each component.
It realizes that process is:
Step one:Injecting structure body injector is provided:
Injector has two members values and parent.Values is used to preserve the parameter of injection, and it is a use
Reflect.Type is key, the key-value pair table Map that reflect.Value is value.
Injector is uniquely defined structure in Inject bags, and all of operation is all based on the structure of injector
Body is realized and operation.Injector has two members values and parent.Values is used to preserve the parameter of injection, and it is one
The key-value pair table Map that individual reflect.Type is key, reflect.Value is value.Following New methods are used to initialize
Injector structures, and return the pointer of a sensing Injector structure.This return value pointer is connect by Injector
Mouth packaging.
Step 2:Type mapping interface TypeMapper, three members of interface regulation are provided, Map functions are used to store
The Map Interface type used during operation, MapTo functions are used for the pointer of the Map Interface type used during storage running;Set
(reflect.Type, reflect.Value) function is used to be inserted directly into the value of map type and mapping;Get
(reflect.Type) function is used to obtain the value of mapping according to the type of mapping.
Step 3:There is provided and perform callee interface Invoker:
Invoker interfaces provide reflection call function Invoke.
Step 4:Grouting socket Applicator is provided:
Applicator represents an interface, and it provides the function that a dependence is mapped to a structure.
Step 5:The function SetParent for arranging father node function is provided:
SetParent arranges the father node of injection.If infusion appliance cannot find the Type mapping of dependence, then it will first be searched
Its father's node whether there is the mapping of dependence, if still do not had, returns a miscue information.
Step 6:The function InterfaceOf of the final example of reflection is provided:
InterfaceOf is the core of whole injector controls reversion, for returning the particular type of reflection.
The incoming parameter of InterfaceOf methods is necessary for the pointer of interface type, can otherwise point out exception.
InterfaceOf methods are the cores of Injector, and the parameter of InterfaceOf methods must be an interface class
The pointer of type, if not then exception throw.The return type of InterfaceOf methods is reflect.Type, because
The member values of Injector is exactly a reflect.Type type when the key-value pair table of key.The effect of this method is in fact
Simply type getparms, without concern for its value.
Step 7:The function New for generating infusion appliance is provided:
New functions are used for returning a newly-generated infusion appliance example.
Step 8:The function Invoke of Dynamic Execution function is provided:
Invoke methods are used for Dynamic Execution function, can be by Map or MapTo come injection parameter, because passing through before execution
The function that Invoke is performed can take out the parameter having been injected into, and then be called by the Call methods in reflect bags.Invoke
Parameter f of reception is an interface type, but the bottom-layer-type of f is necessary for function, otherwise can exception throw
Step 9:The function Apply that field to structure is injected is provided:
Apply methods are that, for injecting to the field of struct, parameter is the pointer for pointing to bottom-layer-type for structure.Can
The premise of injection is:Field must be derived (namely field name with capitalization beginning), and the tag of this field is set to
inject。
In the present invention, by way of realizing interface, the task to performing during operation is decoupled:Control reversion is one
The uncoupled thought in soft project is planted, calls class to only rely on interface, and be independent of concrete implementation class, reduce coupling.
Control has given container, when operation just by container determines by concrete implementation dynamically " injection " to calling the right of class
As in;
Code structure designer can only focus on module interface design:High-level module should not rely upon the mould of low level
Block, they should depend on abstract and interface.
Code structure user can only focus on the interface of agreement, and be not concerned with overall structure:The use of abstract and interface
Person only focuses on how to realize interface, but will not pay close attention to the runtime environment at interface place.
Seamless replacement during operation, and do not affect the operation of overall applicability program:Any one same module or same
Realization under interface, can not affected with seamless replacement by when compiling, hot plug pattern when in simple terms this is a kind of operation.
By specific embodiment above, the those skilled in the art can readily realize the present invention.But should
Work as understanding, the present invention is not limited to above-mentioned specific embodiment.On the basis of disclosed embodiment, the technical field
Technical staff can the different technical characteristic of combination in any, so as to realize different technical schemes.
In addition to the technical characteristic described in description, the known technology of those skilled in the art is.
Claims (6)
1. it is a kind of based on go language control inversion component implementation method, it is characterised in that by go language with self-defined construction
Function call injection, the mode of attribute injection arrange the container required for control reversion, and it implements process and is:
Injecting structure body is provided first, and subsequent operation is realized based on the structure;
Then Type mapping interface is provided, for injection parameter and when calling the parameter being injected into is obtained;
There is provided and perform callee interface, the interface provides a reflection call function;
There is provided grouting socket, there is provided a dependence is mapped to the function of a structure;
The function for arranging father node function is provided;
The function of the final example of reflection is provided, for returning the particular type of reflection;
The function for generating infusion appliance is provided, for returning a newly-generated infusion appliance example;
The function of Dynamic Execution function is provided, for Dynamic Execution function;
The function that the field to structure is injected is provided, for injecting to the field of structure, parameter is sensing bottom
Channel type is the pointer of structure.
2. it is according to claim 1 it is a kind of based on go language control inversion component implementation method, it is characterised in that it is described
Two member variables are included in structure body:Values and parent, wherein values are used to preserve the parameter of injection, and it is one
Key-value pair table Map.
3. it is according to claim 1 it is a kind of based on go language control inversion component implementation method, it is characterised in that type
Map Interface includes key-value pair table function, Set functions, Get functions, and wherein key-value pair table function is used for injection parameter, including Map
With MapTo functions, the Map Interface type used when Map functions are for storage running, use when MapTo functions are for storage running
The pointer of the Map Interface type for arriving;Set functions are used to be inserted directly into the value of map type and mapping;Get functions are used for basis
The type of mapping obtains the value of mapping, obtains the parameter being injected into.
4. it is according to claim 1 it is a kind of based on go language control inversion component implementation method, it is characterised in that arrange
The function of father node function is used to arrange the father node of injection, and when infusion appliance cannot find Type mapping, infusion appliance is by being somebody's turn to do
Function lookup its father node whether there is the mapping of dependence, if still do not had, returns a miscue information.
5. it is according to claim 1 it is a kind of based on go language control inversion component implementation method, it is characterised in that provide
Reflecting the function of final example is used for the type that gets parms, and its incoming parameter is the pointer of interface type, and its return type is knot
The key assignmentses of key-value pair table in structure body.
6. it is according to claim 1 it is a kind of based on go language control inversion component implementation method, it is characterised in that generate
The function of infusion appliance is used for initialisation structures body, and returns the pointer of a direction structure body, and this return value pointer is by structure
Body interface is packed.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201611000129.8A CN106569835A (en) | 2016-11-14 | 2016-11-14 | Realization method for inversion-of-control assembly based on go language |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201611000129.8A CN106569835A (en) | 2016-11-14 | 2016-11-14 | Realization method for inversion-of-control assembly based on go language |
Publications (1)
Publication Number | Publication Date |
---|---|
CN106569835A true CN106569835A (en) | 2017-04-19 |
Family
ID=58542677
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201611000129.8A Pending CN106569835A (en) | 2016-11-14 | 2016-11-14 | Realization method for inversion-of-control assembly based on go language |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN106569835A (en) |
Cited By (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN108733353A (en) * | 2017-04-21 | 2018-11-02 | 中兴通讯股份有限公司 | A kind of Interface Construction method and apparatus |
CN109359055A (en) * | 2018-12-19 | 2019-02-19 | 北京东土科技股份有限公司 | A kind of method and apparatus of data test |
CN109800057A (en) * | 2019-01-18 | 2019-05-24 | 杭州复杂美科技有限公司 | Object reference method, equipment and storage medium |
WO2019227899A1 (en) * | 2018-05-31 | 2019-12-05 | 北京三快在线科技有限公司 | Program calling decoupling |
CN111324336A (en) * | 2020-01-20 | 2020-06-23 | 北京无限光场科技有限公司 | Method, device, terminal and storage medium for realizing dependency injection |
Citations (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN102566992A (en) * | 2010-12-17 | 2012-07-11 | 卓望数码技术(深圳)有限公司 | Dependency injection method and dependency injection device based on system running |
CN102609255A (en) * | 2012-01-19 | 2012-07-25 | 中国科学院计算机网络信息中心 | Generation method for Spring IOC (Inversion of Control) configuration file |
-
2016
- 2016-11-14 CN CN201611000129.8A patent/CN106569835A/en active Pending
Patent Citations (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN102566992A (en) * | 2010-12-17 | 2012-07-11 | 卓望数码技术(深圳)有限公司 | Dependency injection method and dependency injection device based on system running |
CN102609255A (en) * | 2012-01-19 | 2012-07-25 | 中国科学院计算机网络信息中心 | Generation method for Spring IOC (Inversion of Control) configuration file |
Non-Patent Citations (1)
Title |
---|
JEREMY SAENZ,ETC: "https://github.com/codegangsta/inject/blob/master/inject.go", 《INJECT.GO》 * |
Cited By (9)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN108733353A (en) * | 2017-04-21 | 2018-11-02 | 中兴通讯股份有限公司 | A kind of Interface Construction method and apparatus |
CN108733353B (en) * | 2017-04-21 | 2023-08-08 | 中兴通讯股份有限公司 | Interface construction method and device |
WO2019227899A1 (en) * | 2018-05-31 | 2019-12-05 | 北京三快在线科技有限公司 | Program calling decoupling |
CN109359055A (en) * | 2018-12-19 | 2019-02-19 | 北京东土科技股份有限公司 | A kind of method and apparatus of data test |
CN109359055B (en) * | 2018-12-19 | 2022-04-15 | 北京东土科技股份有限公司 | Data testing method and device |
CN109800057A (en) * | 2019-01-18 | 2019-05-24 | 杭州复杂美科技有限公司 | Object reference method, equipment and storage medium |
CN109800057B (en) * | 2019-01-18 | 2021-06-01 | 杭州复杂美科技有限公司 | Object calling method, device and storage medium |
CN111324336A (en) * | 2020-01-20 | 2020-06-23 | 北京无限光场科技有限公司 | Method, device, terminal and storage medium for realizing dependency injection |
CN111324336B (en) * | 2020-01-20 | 2023-12-12 | 北京有竹居网络技术有限公司 | Method, device, terminal and storage medium for implementing dependency injection |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN106569835A (en) | Realization method for inversion-of-control assembly based on go language | |
CN105845137B (en) | A kind of speech dialog management system | |
Bracha et al. | Modules as objects in Newspeak | |
Posse et al. | An executable formal semantics for UML-RT | |
Bock | UML 2 Activity and Action Models. | |
Müller et al. | Modular specification of frame properties in JML | |
Syriani et al. | De-/re-constructing model transformation languages | |
WO2020215686A1 (en) | Spring framework generic dependency injection method and apparatus, computer device and storage medium | |
Qin et al. | A semantic foundation for TCOZ in unifying theories of programming | |
Chiba et al. | Aspect-oriented programming beyond dependency injection | |
Van Mierlo et al. | SCCD: SCCDXML extended with class diagrams | |
Omicini et al. | Formal specification and enactment of security policies through Agent Coordination Contexts | |
Naumann | Autosar runtime environment and virtual function bus | |
Driessen et al. | Shifting temporal and communicational aspects into design phase via AADL and RTSJ | |
Müller et al. | Modular specification of frame properties in JML | |
Crane et al. | Towards a formal account of a foundational subset for executable UML models | |
Jamart et al. | A reflective approach to process model customization, enactment and evolution | |
Cano et al. | Session-based concurrency, reactively | |
CN107765655B (en) | Method, system and readable medium for extending MES function by message routing system | |
de Boer et al. | Termination detection for active objects | |
Wobcke | Modelling PRS-like agents’ mental states | |
Atkinson et al. | Controlling view editability in projection-based modeling environments | |
Miyazawa et al. | SCJ-Circus: specification and refinement of Safety-Critical Java programs | |
Bunting et al. | A meta-metamodel for dynamic constraint feedback in modeling languages | |
Poetzsch-Heffter et al. | Verification of actor systems needs specification techniques for strong causality and hierarchical reasoning |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
RJ01 | Rejection of invention patent application after publication | ||
RJ01 | Rejection of invention patent application after publication |
Application publication date: 20170419 |