Start to do this project, found unable to complete the first design, re-coding, so decided to sub-module, from the Administrator module design, coding, and the interface has been changed several times.
The administrator module involves features such as login and background maintenance for administrators, which also involve front-end development. UI templates use Inspinia, feeling that this set of templates feature rich, beautiful interface, and based on HTML5 and Bootstrap, these two aspects of knowledge can be more understanding.
In the previous article < How to isolate orm> in unit testing, the problem of how to test the service layer to build a pseudo-object was resolved, and then the service layer and unit test of the Administrator module were completed in parallel, and the front-end template-based interface was better.
Background Login Interface:
Home:
The maintenance of the Administrator is not yet complete, and here are two previously encountered issues: asynchronous-commit validation of HTML5 forms and an issue with AUTOFAC initialization of objects to be injected.
Asynchronous commit validation for a HTML5 form
A) Form validation
Originally planned form validation using ValidForm components, but encountered some inexplicable unresolved style problems, have to use the HTML5 comes with the form validation, directly support email, URL, etc., but there are restrictions on the browser
In addition, even if the browser support, but the feeling of verification is not strict, such as the mailbox input like [email protected] Unexpectedly can also be verified, so or write your own regular expression. Non-null Check to add the required property separately.
b) Form Asynchronous commit
HTML5 native Check color than ValidForm beautiful, but only know the need to click the Submit button to trigger the check, which is the direct reason to discard the native check attempt validform, but ValidForm, had to seek the HTML asynchronous submission method, Actually very convenient:
In the registered $ ("#formLogin"). Submit method, use $ (this). Ajaxsubmit (options) replaces the event behavior at the time of clicking Submit, making Ajax asynchronous commits.
Two about AUTOFAC, the configuration problem when the constructor of the object to be injected needs parameters
In order to isolate EF during unit testing of the service layer, the Irepositoty interface and its implementation are added between the service layer and EF operations. To pass the Adminuserrepository parameter in its constructor when initializing Adminuserservice
It can be passed manually during unit testing, but it is not possible to inject adminuserservice into the controller, it is necessary to configure the AUTOFAC to be used in initializing Adminuserservice irepository< The Adminuserentity> object.
In Autofacconfig's code, the simplest case is that only the implementation classes that register the controller and the IService interface need to be registered, and now it is also necessary to register the class with the end of Reposiroty (A.name.endswith ("Repository") ), as it is stipulated here that the IRepository class unification ends with "Repository" and then through builder. Register (A = new Adminuserservice (irepository<adminuserentity>) A.resolve (typeof (irepository< adminuserentity>))) to configure AUTOFAC to pass the arguments to the constructor when initializing the Adminuserservice class as irepository<adminuserentity>. With this configuration, it means that the subsequent addition of the new service class will come back here to establish manual mapping, obviously a bit inconvenient, there should be a more convenient way to test.
MVC and Unit Testing practice of Fitness website (ii)-Administrator module