#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.”




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.


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.

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<>));

Reference
1 Comment