This article mainly introduces about the development of chat framework Dependency injection, container and appearance mode (upper), has a certain reference value, now share to everyone, the need for friends can refer to
I. Dependency injection and decoupling
Love in the men and women, often say, leave you, I will not
First of all:1. Dependency injection is a way to define an interface in a class that needs to use it, regardless of how this interface is implemented, just execute this method2. Dependency injection allows the class to implement genericCode:1. Define a beverage interface1 PackageCn.lonecloud.model;
Broadly divided into: Field injection, construction injection, setter injectionWhere Field injections are considered harmful:1. Violation of the single principleWhen there are multiple dependencies in a class, you don't see a lot of dependencies if you just use Field injection. By using the construct injection \setter
1. Concept IntroductionAs I said earlier, the core of the IOC container control inversion is di--dependency injection. Dependencies between objects are only implemented in the following ways: arguments to constructors, parameters of factory methods, or setting properties for objects created by constructors or factory methods. So, the work of the IOC container is to inject those dependencies when the bean is
on the user ID@Resource (name = "Userdao")Private basedao5). When there are multiple implementation classes in an interface, the instance binding methodThere are two kinds of binding methods@1, @Qualifier annotationsThrough this indicator, it shows which implementation class is what we need.Http://www.cnblogs.com/smileLuckBoy/p/5801678.html@2, @PrimaryUse @primary to tell spring to choose which specific implementation to prioritize when hesitating.Ht
Asp.net core dependency injection, asp. netcore
Recently,. net core can be used across platforms. This is a great thing. In order to catch up with the cross-platform deployment tide two years later, I also joined the learning column. Today I am studying dependency injection, but I found a problem that has plagued me fo
Individual study notes, from Acode.1. TerminologyControl inversion/Reverse control, English full name "inversion of Control", referred to as IOC.Dependency Injection, English full name "Dependency injection", referred to as DI.It is said that Martin Fowler after a deep exploration of the principle of inversion of control, a new name called "
() { Viewbag.show = _service. Getmaindata (); return View (); }}} View code for the main project:@{Viewbag.title = "Home page";}Divclass="Jumbotron "> H1>asp.netH1> Pclass="The lead ">asp.net are a free web framework for building great Web sites and Web applications using HTML, CSS and JavaScript.P> P>a href= " http://asp.net "class=" btn Btn-primary btn-large ">learn more»a>div>div class= "row" > p> here is the main project of AUTOFAC inj
object) in a way that becomes an external injection.
implementing Ioc/di with the Spring framework
1, import spring framework;
2. Create an instance in the configuration file
Class: Represents the name of the category.
Id/name: Instance name 3, obtaining instances of spring configuration
1 ApplicationContext class.
Newfilesystemxmlapplicationcontext ("Src/applicationcontext.xml");
One setter method Injection
The configuration file is as follows:
Code in the action Implementation class:
Private IHelloService helloservice;Private String name;Public void sayHello (){Helloservice. sayHello ();System. out. println (this. name );}
Public void setHelloservice (IHelloService helloservice ){This. helloservice = helloservice;}
Public void setName (String name ){This. name = name;}
Here, both name and helloservice use the setter method o
Spring.net QuickStart: Controlling rollover, Dependency injection, tangent-oriented programmingSpring.net main functions:1.IoC: Control rollover (inversion of controls) understood as abstract factoryRollover control: The right to create objects is controlled by the developer himself, and is transferred to the container.2.DI:
First, dependency injection is basically three ways:1, the first is the setter injection, it can be understood to assign a value to the property of the interface type in the customer class, call different service types according to the actual type of the property, which may use the policy mode;2, through the constructo
Document directory
1.3 default binding
2.1 built-in Scope
Java context and dependency injection (JSR 299) [1]
Reprinted by the author:By: 88250Blog: http:/blog.csdn.net/dl88250MSN Gmail QQ: DL88250@gmail.com
Summary
This article starts with the JSR 299 specification, sorts out and translates very important concepts in this specification, and describes the use of JSR 299 in combination with some short
holds the object, and then gives it to the A object, as to how spring creates that object, and when to create the object's , a object does not need to care about these details (when you were born, how it was born I do not care, can help me to work on the line), a get spring to our object, two people together to complete the work to complete.So the control reversal IoC (inversion of control) is to say that the creation of the object is transferred, the initiative of the previously created object
Thank http://blog.xiaohansong.com/2015/10/21/IoC-and-DI/for the map
1. What is control. As shown in the following figure, we see the object in the software system
high coupling phenomenon. The rotation of all gears is controlled by an object., such as Class B.
2. What is control reversal. is used to object
to decouple。
Decoupling between objects that have dependencies with third-party implementations. This third party is the IOC container. Once
Array supported during runtime configuration
Class Foot {
Public Foot (IBar [] bars)
{}
}
Container. Configure
Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->Container. configure
Configure containers during running
1. Configure constructors, attributes, and method injection.
You can directly create and load configurations during running to configure the Unity container to implement the
that implements the IHttpHandler interface final processing request.4. Call the BeginProcessRequest method in Mvchandler to continue processing the request, and obtain the Controller and action information from the information resolved in 1 in the method, The Controller object is then activated using 2 types of Icontrollerfactory objects, and the corresponding action is eventually executed.The first of these methodsFrom the above
) { _dal.Insert(commandText); }}
Finally, to truly complete dependency injection, AtuoFac will be launched:
var builder = new ContainerBuilder(); builder.RegisterType
From the preceding examples, we can see that the use of AutoFac is a bit like that of Unity. The key thing is the Container class.2. Description of common AutoFac methods (1) builder
Angularjs All functional components are organized in the form of dependency injection, and all components must be decoupled by means of containers (injectors) to access each other;1. The injector stores all recipes (name + class constructors): When Angualrjs starts, the component (Provider) is first registered by name in the injector;2, the component requires a $
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.