forked from RIteshSolidity/MicrosServices
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCustomers.cs
57 lines (52 loc) · 2.08 KB
/
Customers.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using System;
using System.Collections.Generic;
using System.Fabric;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.ServiceFabric.Data.Collections;
using Microsoft.ServiceFabric.Services.Communication.Runtime;
using Microsoft.ServiceFabric.Services.Runtime;
using Microsoft.ServiceFabric.Services.Remoting.Runtime;
using CustomersLibrary;
namespace Customers
{
/// <summary>
/// An instance of this class is created for each service replica by the Service Fabric runtime.
/// </summary>
internal sealed class Customers : StatefulService, ICustomerService
{
private ICustomerRepository _repo;
public Customers(StatefulServiceContext context)
: base(context)
{ }
public async Task<IEnumerable<CustomerEntity>> GetAllCustomers()
{
return await _repo.GetAllCustomers();
}
public async Task NewCustomer(CustomerEntity cust)
{
await _repo.AddCustomer(cust);
}
/// <summary>
/// Optional override to create listeners (e.g., HTTP, Service Remoting, WCF, etc.) for this service replica to handle client or user requests.
/// </summary>
/// <remarks>
/// For more information on service communication, see https://aka.ms/servicefabricservicecommunication
/// </remarks>
/// <returns>A collection of listeners.</returns>
protected override IEnumerable<ServiceReplicaListener> CreateServiceReplicaListeners()
{
return this.CreateServiceRemotingReplicaListeners();
}
/// <summary>
/// This is the main entry point for your service replica.
/// This method executes when this replica of your service becomes primary and has write status.
/// </summary>
/// <param name="cancellationToken">Canceled when Service Fabric needs to shut down this service replica.</param>
protected override async Task RunAsync(CancellationToken cancellationToken)
{
_repo = new CustomerRepository(this.StateManager);
}
}
}