Dependency Injection – ASP.NET  

Dependency Injection –  ASP.NET  

Introduction:

By taking a closer look on a Dependency Injection (DI) , we can understand it is a software design pattern which allows us to develop a loosely coupled code and it also decreases the code dependency of components of the tightly coupled software. It is also known as Inversion-of-Control, which helps us to do the unit testing more convenient.

Advantages of using Dependency Injection are:

1. Increases code re usability

.2. Reduces class coupling

3. Improves code maintainability

4. Improves application testing

Basic CRUD Operations & Scaffold Templates

  1. File -> New Project-> Visual C# -> ASP.NET      Web Application-> OK
  2. Select MVC,      Change Authentication = No Authentication->OK
  3. Create a two table in the new database in Sql Server as Department and Employee
  4. Right Click on Project ->Add New Item-> Under Visual C#, Data Select ADO.NET Entity Data Model, Name = DeccansoftEntity -> Add
  5.  Select EFDesigner from database -> Next
  6.  New Connection -> Select Server Name = ADMIN-PC\SQLEXPRESS2017, database name = Deccansoft -> OK -> Next -> Select Entity Framework 6.x -> Next
  7. Expand tables and Select all the tables (Department and Employee)which we have created on the step 3 -> Finish
  8. Solution Explorer -> Right click on Controller -> New -> Controller -> MVC 5 Controller with Views using Entity Framework ASP.NET MVC 5.X CRUD Operations
  9. Model Class=Employee, DataContextClass=EFDemoDbEntities,ControllerName=EmployeesController ->Add 10. Build and run the application

Writing Generic Class/Repository

1. To project add the following Generic class in the Repository folder

2. Create a new folder, Name=BO.

3. Under BO folder, add the Employee BO class to the project.

4. Under BO Folder, add the Department BO class to the project.

4.1 Under BO Folder, add Context Helper class to the project

Dependency Injection and Custom Controller Factory

4.2 Add-> Global.asax in below code

4.3 To separate the creation of the dependencies from the main class we use Dependency injection technique, so we typically inject an object which is needed by a class through a constructor.

5.  Edit the code of Employees Controller as below-

5.1 Create Index Action Result in a Controller as below

5.2 Create Index Action Result method view(Index-> Add View-> View name=Index, Template=List, Model class = Employee, Data Context class=DeccansoftEntities -> Add)

5.3 Display Index View in Browser

6. Edit the code of Employees Controller, write a Create Action method as below.

6.1 Create Action Result method View (Create->Add View->View name=Create, Template=Create,Model class=Employee,Data Context= DeccansoftEntities -> Add)

6.2 Create Index Action Result in a Controller as below

6.3 Display Create View in Browser

7. Edit the code of Employees Controller, Write a Edit Action method as below.

7.1 Edit Action Result method View (Edit->Add View->View name=Edit, Template=Create,Model class=Employee,Data Context=DeccansoftEntities->Add)

7.2 Create Edit Action Result method in a Controller as below

7.3 Display Edit View in Browser

8. Edit the code of Employees Controller, write a Details Action method as below.

8.1 Details Action Result method View (Create->Add View->View name=Details, Template=Details,Model class=Employee,Data Context=DeccansoftEntities->Add)

8.3 Display Details View in Browser

9. Edit the code of Employees Controller, Write a Delete Action method as below.

9.1 Delete Action Result method View (Create->Add View->View name=Delete, Template=Delete,Model class=Employee, Data Context=DeccansoftEntities->Add)

9.2 Create Delete Action Result in a Controller as below

9.3 Display Details View in Browser

Please follow and like us:
0

Web Programming Introduction. Best Dot Net Training

Web Programming Introduction. Best Dot Net Training

HTTP Protocol

  • The communication between web server and web browser on the internet is done using HTTP protocol.

  • HTTP is a W3C specification.

  • HTTP Protocol is the safest protocol on the internet.

  • HTTP is a stateless protocol. This is because it doesn’t know whether the request that has been made is part of an ongoing correspondence or just a single message.

  • HTTP communicates only in the String Format and is thus virus free and is platform independent.

    HTTP protocol works on PULL technology. i.e. we can pull everything available on the web server but we cannot push content to the server unless the server allows for it.

Continue reading “Web Programming Introduction. Best Dot Net Training”

Please follow and like us:
0

The value of Hidden Field can be programmatically set. Best Dot Net Training

The value of Hidden Field can be programmatically set. Best Dot Net Training

  1. Like ViewState, HiddenField is also used for managing the state of the client in round trips to the same web form.

  2. ViewState is managed by Page framework but HiddenField has to be coded by us.

  3. It can store data which is of type string and cannot store serializable custom objects unlike ViewState

  4. The value of HiddenField can be programmatically set on the client using Javascript, the same can be retrieved from the server from the HiddenField object

    Example:-To get DateTime of the client when the form was posted

Continue reading “The value of Hidden Field can be programmatically set. Best Dot Net Training”

Please follow and like us:
0

Validation Controls in the browser before the form is submitted to the serve

Validation Controls in the browser before the form is submitted to the server

Validation Controls

These controls are used for validating controls in the browser before the form is submitted to the server

BaseValidator

It is the parent of all the validation controls.

Validation Controls inherited from BaseValidator control are:

RequiredFieldValidator, RangeValidator, CompareValidator, RegularExpressionValidator, CustomValidator.

Properties of BaseValidator:

ControlToValidate, ErrorMessage, Text, Display (Static/Dynamic/None), SetFocusOnError, ToolTip, EnableClientScript (to disable client side validations), ValidationGroup

Continue reading “Validation Controls in the browser before the form is submitted to the serve”

Please follow and like us:
0