-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixed module implementation with interface segregation
- Loading branch information
Showing
15 changed files
with
100 additions
and
27 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,45 @@ | ||
using System; | ||
using Infrastructure.Module; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace Implementation.Module | ||
{ | ||
/// <inheritdoc /> | ||
public abstract class AModule : IModule | ||
{ | ||
protected IServiceCollection Collection; | ||
|
||
/// <inheritdoc cref="IModule.IsRegistered"/> | ||
public bool IsRegistered { get; } = false; | ||
|
||
protected AModule(IServiceCollection collection) | ||
{ | ||
Collection = collection ?? throw new ArgumentNullException(nameof(collection)); | ||
} | ||
|
||
public virtual IServiceCollection RegisterServices() | ||
{ | ||
if (IsRegistered) | ||
{ | ||
return Collection; | ||
} | ||
|
||
RegisterServices(Collection); | ||
|
||
return Collection; | ||
} | ||
|
||
public abstract IModule RegisterServices(IServiceCollection collection); | ||
|
||
public virtual IModule RegisterOtherServices(IBaseModule module) | ||
{ | ||
if (module.IsRegistered) | ||
{ | ||
return this; | ||
} | ||
|
||
module.RegisterServices(Collection); | ||
return this; | ||
} | ||
} | ||
} |
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
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,18 @@ | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace Infrastructure.Module | ||
{ | ||
public interface IBaseModule | ||
{ | ||
/// <summary> | ||
/// Shows whether the modules is already registered or not. | ||
/// </summary> | ||
bool IsRegistered { get; } | ||
|
||
/// <summary> | ||
/// Registers the services into the specified collection. | ||
/// </summary> | ||
/// <param name="collection">The <see cref="IServiceCollection"/> created in the composition root.</param> | ||
IModule RegisterServices(IServiceCollection collection); | ||
} | ||
} |
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
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