-
-
Save hazzik/3278770 to your computer and use it in GitHub Desktop.
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 IoCAwareScanner : DefaultModelMetadataScanner | |
{ | |
private readonly Action<Type, Type> registerAsTransient; | |
internal static readonly Type ModelMetadataConfigurationType = typeof(IModelMetadataConfiguration); | |
protected IoCAwareScanner(Action<Type, Type> registerAsTransient) | |
{ | |
this.registerAsTransient = registerAsTransient; | |
} | |
public override IEnumerable<IModelMetadataConfiguration> GetConfigurations() | |
{ | |
RegisterTypes(); | |
return DependencyResolver.Current.GetServices<IModelMetadataConfiguration>(); | |
} | |
private void RegisterTypes() | |
{ | |
IEnumerable<Assembly> referencedAssemblies = GetReferencedAssemblies(); | |
var configurationTypes = FilterConfigurationTypes(referencedAssemblies.SelectMany(a => a.GetLoadableTypes())); | |
foreach (Type type in configurationTypes) | |
{ | |
registerAsTransient(ModelMetadataConfigurationType, type); | |
} | |
} | |
} |
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 abstract class IoCAwareScanner : DefaultModelMetadataScanner | |
{ | |
internal static readonly Type ModelMetadataConfigurationType = typeof(IModelMetadataConfiguration); | |
public override IEnumerable<IModelMetadataConfiguration> GetConfigurations() | |
{ | |
RegisterTypes(); | |
return DependencyResolver.Current.GetServices<IModelMetadataConfiguration>(); | |
} | |
protected abstract void RegisterAsTransient(Type implementationType, Type serviceType = null); | |
private void RegisterTypes() | |
{ | |
IEnumerable<Assembly> referencedAssemblies = GetReferencedAssemblies(); | |
var configurationTypes = FilterConfigurationTypes(referencedAssemblies.SelectMany(a => a.GetLoadableTypes())); | |
foreach (Type type in configurationTypes) | |
{ | |
RegisterAsTransient(ModelMetadataConfigurationType, type); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment