Nopcommerce Dependency Class Generation container

Source: Internet
Author: User

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

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.