This repository has been archived by the owner on Apr 13, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
119 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace BeatPulse.Core | ||
{ | ||
public class BeatPulseFactoryRegistration : IBeatPulseLivenessRegistration | ||
{ | ||
private readonly Func<IServiceProvider, IBeatPulseLiveness> _creator; | ||
|
||
public string Path { get; } | ||
public Guid Id { get; } | ||
|
||
public BeatPulseFactoryRegistration(string path, Func<IServiceProvider, IBeatPulseLiveness> creator) | ||
{ | ||
_creator = creator ?? throw new ArgumentNullException(nameof(creator)); | ||
Id = Guid.NewGuid(); | ||
Path = path; | ||
} | ||
|
||
public IBeatPulseLiveness GetOrCreateLiveness(IServiceProvider sp) => _creator.Invoke(sp); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace BeatPulse.Core | ||
{ | ||
public class BeatPulseInstanceRegistration : IBeatPulseLivenessRegistration | ||
{ | ||
|
||
private readonly IBeatPulseLiveness _instance; | ||
|
||
public string Path => _instance.Path; | ||
public Guid Id { get; } | ||
|
||
public BeatPulseInstanceRegistration(IBeatPulseLiveness liveness) | ||
{ | ||
_instance = liveness ?? throw new ArgumentNullException(nameof(liveness)); | ||
Id = Guid.NewGuid(); | ||
} | ||
|
||
public IBeatPulseLiveness GetOrCreateLiveness(IServiceProvider sp) => _instance; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace BeatPulse.Core | ||
{ | ||
public static class BulsePulseContextExtensions | ||
{ | ||
public static BeatPulseContext Add(this BeatPulseContext ctx, IBeatPulseLiveness liveness) | ||
=> ctx.Add(new BeatPulseInstanceRegistration(liveness)); | ||
public static BeatPulseContext Add(this BeatPulseContext ctx, string path, Func<IServiceProvider, IBeatPulseLiveness> creator) | ||
=> ctx.Add(new BeatPulseFactoryRegistration(path, creator)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace BeatPulse.Core | ||
{ | ||
public interface IBeatPulseLivenessRegistration | ||
{ | ||
Guid Id { get; } | ||
string Path { get; } | ||
IBeatPulseLiveness GetOrCreateLiveness(IServiceProvider sp); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters