File tree Expand file tree Collapse file tree 5 files changed +10
-8
lines changed Expand file tree Collapse file tree 5 files changed +10
-8
lines changed Original file line number Diff line number Diff line change @@ -50,7 +50,7 @@ public async Task FindAndDeleteProductAsync()
50
50
public async Task DisplayProductsAsync ( )
51
51
{
52
52
var number = 1 ;
53
- foreach ( var product in await _repository . GetAllProductsAsync ( ) )
53
+ await foreach ( var product in _repository . GetAllProductsAsync ( ) )
54
54
{
55
55
Console . WriteLine ( $ "[{ number ++ } ] { product } ") ;
56
56
}
Original file line number Diff line number Diff line change @@ -7,17 +7,19 @@ public class MemoryProductDao : IProductDao
7
7
{
8
8
private readonly List < Product > _products = [ ] ;
9
9
10
- public Task < IEnumerable < Product > > GetAllProductsAsync ( )
10
+ public async IAsyncEnumerable < Product > GetAllProductsAsync ( )
11
11
{
12
- return Task . FromResult ( _products . AsEnumerable ( ) ) ;
12
+ foreach ( var product in _products )
13
+ {
14
+ yield return product ;
15
+ }
13
16
}
14
17
15
18
public Task < Product ? > GetProductByNameAsync ( string productName )
16
19
{
17
20
return Task . FromResult ( _products . FirstOrDefault ( p => p . Name == productName ) ) ;
18
21
}
19
22
20
-
21
23
public Task DeleteProductByNameAsync ( string productName )
22
24
{
23
25
_products . RemoveAll ( p => p . Name == productName ) ;
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ namespace SimpleInventoryManagementSystem.Interfaces;
4
4
5
5
public interface IProductDao
6
6
{
7
- Task < IEnumerable < Product > > GetAllProductsAsync ( ) ;
7
+ IAsyncEnumerable < Product > GetAllProductsAsync ( ) ;
8
8
Task < Product ? > GetProductByNameAsync ( string productName ) ;
9
9
Task DeleteProductByNameAsync ( string productName ) ;
10
10
Task AddProductAsync ( Product product ) ;
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ namespace SimpleInventoryManagementSystem.Interfaces;
4
4
5
5
public interface IProductRepository
6
6
{
7
- Task < IEnumerable < Product > > GetAllProductsAsync ( ) ;
7
+ IAsyncEnumerable < Product > GetAllProductsAsync ( ) ;
8
8
Task < Product ? > GetProductByNameAsync ( string productName ) ;
9
9
Task DeleteProductByNameAsync ( string productName ) ;
10
10
Task AddProductAsync ( Product product ) ;
Original file line number Diff line number Diff line change @@ -8,8 +8,8 @@ public class ProductRepository : IProductRepository
8
8
private readonly IProductDao _productDao ;
9
9
public ProductRepository ( IProductDao productDao ) => _productDao = productDao ;
10
10
11
- public async Task < IEnumerable < Product > > GetAllProductsAsync ( ) =>
12
- await _productDao . GetAllProductsAsync ( ) ;
11
+ public IAsyncEnumerable < Product > GetAllProductsAsync ( ) =>
12
+ _productDao . GetAllProductsAsync ( ) ;
13
13
14
14
public async Task < Product ? > GetProductByNameAsync ( string productName ) =>
15
15
await _productDao . GetProductByNameAsync ( productName ) ;
You can’t perform that action at this time.
0 commit comments