Nopcommerce
To achieve a loosely coupled frame design
Using the IOC framework: AUTOFAC---performance is good
The components in the IOC need to be registered in the IOC first:
Spring.net registering with a configuration file
StructureMap to register with features
AUTOFAC to register via proxy
One of the IOC principles: interface and implementation separation, so IOC is declaring a specific class implements an interface. Then use the system to get the implementation class of the interface from the IOC and create the object.
In Autofac, objects are also called components. The lifecycle of a component is divided into: singleton, temporal, and life cycle domains.
Namespace Nop.Core.Infrastructure.DependencyManagement
{
public enum Componentlifestyle
{
Singleton = 0,
Transient = 1,
Lifetimescope = 2
}
}
There are containers in the AUTOFAC
1. and provides methods for registering interfaces and their types.
2. The method is also provided to find the type of registration.
3. Automatically create objects.
Type finder:
1. To support plug-in features
2. In order to support the automatic registration function.
Itypefinder and implementation classes provide this functionality.
You can find:
1. Classes in this program domain
2. Classes in all dynamic-link libraries in the entire bin directory.
and register these classes in the IOC container (Type reversal container)
Type registration
Container Management class: Containermanager Manage containers generated through AUTOFAC
Container Configuration class: Containerconfigurer Establish the relationship between type-dependent registration <-----> Type Lookup Classes
Dependent class Engine: Enginecontext can be generated from the configuration file engine, which is responsible for returning objects from the container based on the type interface.
System default Engine: Nopengine If a valid engine is not configured, a default engine is used, and the generated engine is saved in a singleton container.
Initialize: The system initializes the engine context in the method Application_Start of the class mvcapplication. and by calling Engineecontext.initialize (false) to implement all reversal-dependent registrations.
Container Registration class:
Nopcommerce Dependency Class Generation container