#2 Web Application Project

This sample will show the interface class method’s iterator pattern sample in the web application situation because the interface class methods will be a little challenging to edit when the developers/readers write this pattern code in the web application. The abstract class methods are more straightforward than the interface class methods when the developers/readers write this pattern code, but the abstract class running mechanism will be more complicated than the interface class works.

Step 1: Create three interface class files in the Core projects. One interface class file name sets “IIterator.” Another interface class file name sets “IIteratorAggregate.” Other interface class file name sets “IIteratorServices.”

Fig 1 Solution explorer – Interface class files
Fig 2 IIterator interface class source code
Fig 3 IIteratorAggregate interface class source code
Fig 4 IIteratorServices interface class source code

Step 2: Create the Iterator pattern’s BLL layer class files in the Core projects. One class file name sets “ItemCollection,” which function is about collecting every one node data. Another class file name sets “AlphabeticalOrderIterator,” which is about everyone’s data order.

The “ItemCollection” class file inherits the IIteratorAggregate interface class files and adds the IDisposable interface class. The “AlphabeticalOrderIterator” class file inherits the IIterator interface class files and adds the IDisposable interface class. Every one operation should add the dispose function operation in every one function.

Fig 5 ItemCollection class file source code
Fig 6 AlphabeticalOrderIterator class file source code

Step 3: Create the iterator pattern service class files in the Core project, which file name sets “IteratorServices” and inherits the “IIteratorServices” interface class files. Suppose the data has been accessed before executing the iterator pattern operations, then the generic type repository’s GetAll function result assigns to “itemCollection” variables.

Fig 7 IteratorServices class file source code

Step 4: Add the iterator pattern-related files in the web project, such as view flies, controller files. Register the iterator pattern files in the web project’s start.cs file.

services.AddScoped(typeof(IIteratorServices<>), typeof(IteratorServices<>));
Fig 8 Iterator pattern executing result

Reference

1 Comment

Leave a Reply