Last active
May 2, 2018 16:25
-
-
Save Flayed/e8193f995fa8f7e26d1ea7962b357ce4 to your computer and use it in GitHub Desktop.
Reflection Registration
This file contains hidden or 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
public class ConfigurationService : IConfigurationService | |
{ | |
public ConfigurationService(IDataService dataService) | |
{ | |
_configurationSet = dataService.GetConfigurationSet(); | |
} | |
public ITriangleConfiguration TriangleConfiguration => _configurationSet.TriangleConfiguration; | |
public ISquareConfiguration SquareConfiguration => _configurationSet.SquareConfiguration; | |
public ICircleConfiguration CircleConfiguration => _configurationSet.CircleConfiguration; | |
private readonly ConfigurationSet _configurationSet; | |
} |
This file contains hidden or 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
public interface IConfigurationService | |
{ | |
ITriangleConfiguration TriangleConfiguration { get; } | |
ISquareConfiguration SquareConfiguration { get; } | |
ICircleConfiguration CircleConfiguration { get; } | |
} |
This file contains hidden or 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
var builder = new ContainerBuilder(); | |
builder.Register<ConfigurationService>().AsImplementedInterfaces().SingleInstance(); | |
// Register the configurations from the ConfigurationService as their respective interfaces | |
foreach (var property in typeof(IConfigurationService).GetProperties()) | |
{ | |
builder | |
.Register(c => property.GetValue(c.Resolve<IConfigurationService>())) | |
.As(property.PropertyType); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment