NopCommerce FAQ Summary

Source: Internet
Author: User
Tags net thread mercurial nopcommerce

The following lists the issues that programmers often raise when developing nopCommerce. They also showed the nopCommerce team's choice of some architectures.

Article Description: a self-source blog is translated based on the understanding of the original article, rather than the word-based translation style of the publishing house. You are welcome to give your comments. You are also welcome to repost this article, but you must note the original address of this article. For more articles about nopcommerce, please follow the http://www.dingsea.com /? Tag = nopcommerce, or join our QQ Group 101675096

What are the requirements?

The technical and system requirements of NopCommerce can be found here)

How do programmersNopCommerceProject contribution code?

The NopCommerce code is hosted in the codeplex Mercurial code base. You can click here to access it. With this public code library, you can find the modifications to be released and previous design decisions. If you want to know how codeplex Mercurial supports the version tree, please refer to here for more information. Programmers can easily upload plug-ins and language packs on our extension pages and share them with others. To Upload extensions, visit my account in the browser, select the "Your contributions and extensions" tab, and click the "Upload a new extension" button.

How can I report a defect?

NopCommerce uses Codeplex as the official defect tracking system. If a defect is found, it can be reported to the nopCommerce team by creating a task in Codeplex. Programmers or users can post on our Bug Reports forum to inform them of the newly discovered defects. If your defects have been recorded, of course, it is best to verify those that have not been recorded ). Reporting repetitive defects can distract us and reduce our time on new development and change defects.

NopCommerceData access layer

The Nop. Data project contains a series of classes and functions to read and write Data to the database or other Data storage media. The Nop. Data project helps to separate the Data access logic from your business objects. NopCommerce uses Entity Framework (EF) Code-First, Code-First allows programmers to define entities in the source Code (all core entities are in Nop. core Project), and then use EF to generate a C # class-based database. This is why it is called Code-First. You can use LINQ to query your objects. It will quietly convert the code into SQL statements and execute them in the database. Nopcommerce has fluent APIs for Fully customized persistent mappings. For more information about Code-First, visit here and here.

Control inversion and dependency Injection

Control inversion and dependency injection are two inseparable methods used to separate dependencies in your application. Inversion of Control (IoC) means that an object does not create a new object and relies on it to complete the work. Instead, they get the objects they want from the outside. Dependency Injection (DI) means that, without the intervention of objects, it is generally completed by passing in the framework component of the constructor parameters and a series of attributes. Martin Fowler wrote an article about dependency injection and control inversion, so I won't copy it here. You can find it here. NopCommerce uses the Autofac class library as the IOC container. As long as you write a service and the appropriate interface implemented by this service, you shouldIDependencyRegistrarRegister it in the class of the interface (Nop. Core. Infrastructure. DependencyManagement namespace. For example, all core services of nopCommerce are registered in the DependencyRegistrar class of Nop. Web. Framework class library.

Public class DependencyRegistrar: IDependencyRegistrar

{

Public virtual void Register (ContainerBuilder, ITypeFinder typeFinder)

{

Builder. register (c => c. resolve (). request ). as (). instancePerHttpRequest (); builder. register (c => c. resolve (). response ). as (). instancePerHttpRequest ();

You can create any dependent registration classes. Each class implementsIDependencyRegistrarEach interface class hasOrderAttribute, which can be used to replace an existing dependency. To override nopcommerce dependencies, set the order attribute to greater than 0. Nopcommerce sorts dependencies and runs them in order. The larger the number, the sooner your object will be registered.

How do I register a new route? I think it still works.RoutesBetter ?)

ASP. NET routing is mainly used to accept browser requests and map them to specific MVC controller actions. More information is available here. Nopcommerce hasIRouteProviderIs used to register a route when the application starts. All the core routes are in the Nop. Web project.RouteProviderRegister.

Public partial class RouteProvider: IRouteProvider

{

Public void RegisterRoutes (RouteCollection routes)

{

// Home page

Routes. MapLocalizedRoute ("HomePage ",

"",

New {controller = "Home", action = "Index "},

New [] {"Nop. Web. Controllers "});

You can create any RouteProvider. For example, if your plug-in has a custom route and needs to be registered, you can create a new class that implements the IRouteProvider interface, and then register the route according to the plug-in.

Data Verification

Data verification is a process to ensure that the program is operating clean, correct, and useful data. Many. NET Program use Data Annotation Validators, but nopCommerce uses Fluent Validation, which is composed of young literary interfaces and lambda expressions. NET small verification library to generate validation rules that meet your business needs. In nopCommerce, you must add a validation to some models in two steps: 1. create a class that inherits from AbstractValidator and put all the necessary verification logic in it. It is helpful to see the following:

Public class AddressValidator: AbstractValidator {public AddressValidator (ILocalizationService localizationService) {RuleFor (x => x. firstName ). notEmpty (). withMessage (localizationService. getResource ("Address. fields. firstName. required ")). when (x =>! X. FirstNameDisabled );

2. Add the ValidatorAttribute attribute to your model class, for example, the following code:

[Validator (typeof (AddressValidator)]

Public class AddressModel: BaseNopEntityModel

{
When a view model is submitted to the Controller, ASP. NET performs the corresponding validation.

Scheduled tasks

With scheduled tasks, you can schedule a task to run in the background during the specified period. For example, nopCommerce regularly sends emails in the queue. A task is executed by a separate thread in the ASP. NET thread pool. To create a new task, follow these steps:

  1. DefineITaskInterface Class, which has only one non-parameter method:Execute. This method will be called when the task is to be executed, you know.
  2. To set a scheduled task, the programmer must addScheduleTaskRecord. You can useIScheduleTaskServiceTo add records

Event exposure and handling

Events are the part that broadcasts messages to interest you. Events are data-driven, such as adding, updating, and deleting data. NopCommerce allows programmers to "listen" to events they are interested in. There are basically two steps for programmers to play with the event. one programmer can either publish an event for others to use or compile and release the event with another programmer.

  1. To publish an event, a programmer must first obtainIEventPublisherThe instance is then called together with the corresponding dataPublishMethod.
  2. To listen to an event, a programmer must implement a newIConsumerGeneric interface. Once someone uses this event, nopCommerce uses reflection to find and register the implementation of this event.

 

SetAPI

Like other website platforms, nopCommerce also has settings such as "online shop name" or "Enable single-page purchase". There are two ways to manage settings in nopCommerce.

You can useISettingServiceInterface MethodSetSettingAndGetSettingByKeyTo load and save a single setting. In nopCommerce, the best solution is to createISettingServiceInterface. Each setting changes to the C # Attribute. programmers should use the setting class to build function injection settings as needed. The following is the sample code of the setting class.

/* Conclusion: This article is translated based on the understanding of old ding in the original article, rather than the word-based translation style of the publishing house. You are welcome to give your comments. You are also welcome to repost this article, but you must note the original address of this article. For more articles about nopcommerce, please follow the http://www.dingsea.com /? Tag = nopcommerce, or join our QQ Group 101675096 for discussion.
*/
Public class MediaSettings: ISettings

{

Public int AvatarPictureSize {get; set ;}

Public int ProductThumbPictureSize {get; set ;}

Public int ProductDetailsPictureSize {get; set ;}

Public int ProductThumbPictureSizeOnProductDetailsPage {get; set ;}

Public int ProductVariantPictureSize {get; set ;}

Public int CategoryThumbPictureSize {get; set ;}

Public int ManufacturerThumbPictureSize {get; set ;}

Public int CartThumbPictureSize {get; set ;}

 

Public bool DefaultPictureZoomEnabled {get; set ;}

 

Public int MaximumImageSize {get; set ;}

}

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.