public void CommitRegistrationsToContainer() { //RegisterExtensionPointsIntoContainer(_container); TypeRegistrations.Sort((t1, t2) => t1.ExtensionOrderPriority.CompareTo(t2.ExtensionOrderPriority)); AdjustToRunMode(); CheckNoCircularReferences(); RegisterTypesIntoContainer(_container); }
private void AdjustToRunMode() { if (CurrentRunMode == RunMode.Simulator) { IEnumerable <RegisterType> simulatorRegisterTypes = TypeRegistrations.Where(tr => tr.Role == RegistrationRole.SimulatorImplementation); TypeRegistrations.RemoveAll(tr => tr.Role == RegistrationRole.DefaultImplementation && simulatorRegisterTypes.Any(srt => srt.Implements == tr.Implements)); } else { TypeRegistrations.RemoveAll(tr => tr.Role == RegistrationRole.SimulatorImplementation); } }
public void RegisterType(RegisterType type) { switch (type.Role) { case RegistrationRole.DefaultImplementation: //_logger.Info(_logCategory, "RegistrationsManager: Registering Type '{0}' as default implementation for '{1}' Service, Lifetime = {2}", type.ResolvingTypeName, type.Implements.Name, type.Lifetime); break; case RegistrationRole.SimulatorImplementation: //_logger.Info(_logCategory, "RegistrationsManager: Registering Type '{0}' as simulator implementation for '{1}' Service, Lifetime = {2}", type.ResolvingTypeName, type.Implements.Name, type.Lifetime); break; case RegistrationRole.Extension: //_logger.Info(_logCategory, "RegistrationsManager: Registering Extension '{0}' implementing '{1}' Extension Point, Lifetime = {2}", type.ResolvingTypeName, type.Implements.Name, type.Lifetime); break; default: throw new ArgumentOutOfRangeException("type.Role"); } TypeRegistrations.Add(type); }
private void CheckNoCircularReferences() { Dictionary <Type, HashSet <Type> > typeToConstructorParams = new Dictionary <Type, HashSet <Type> >(); foreach (var registerAttribute in TypeRegistrations) { ConstructorInfo[] constructorInfos = registerAttribute.TypeToRegister.GetConstructors(); HashSet <Type> constructorParamTypes = new HashSet <Type>(constructorInfos.SelectMany(ci => ci.GetParameters().Select(p => p.ParameterType.IsArray ? p.ParameterType.GetElementType() : p.ParameterType))); IEnumerable <RegisterType> referencedRegisterTypes = TypeRegistrations.Where(t => constructorParamTypes.Any(p => p == t.Implements)); foreach (RegisterType referencedRegisterType in referencedRegisterTypes) { ConstructorInfo[] referencedConstructorInfos = referencedRegisterType.TypeToRegister.GetConstructors(); HashSet <Type> referencedConstructorParamTypes = new HashSet <Type>(referencedConstructorInfos.SelectMany(ci => ci.GetParameters().Select(p => p.ParameterType.IsArray ? p.ParameterType.GetElementType() : p.ParameterType))); if (referencedConstructorParamTypes.Contains(registerAttribute.Implements)) { throw new CircularClassReferenceException(registerAttribute.TypeToRegister, referencedRegisterType.TypeToRegister); } } } }
// This method gets called by the runtime. Use this method to add services to the container. public IServiceProvider ConfigureServices(IServiceCollection services) { services.AddMvc(); services.AddMemoryCache(); services.AddCors(options => options.AddPolicy("CorsPolicy", builder => { builder.AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader() .AllowCredentials(); })); services.AddSignalR(config => { config.EnableDetailedErrors = true; config.KeepAliveInterval = TimeSpan.FromMinutes(1); }); ApplicationContainer = TypeRegistrations.Register(services, Configuration); return(new AutofacServiceProvider(ApplicationContainer)); }
public static MCSubHeaderRegistration Find(Type type) { TypeRegistrations.TryGetValue(type, out var registration); return(registration); }
/// <summary> /// Register types with the IoC /// </summary> private static void RegisterTypes() { TypeRegistrations.RegisterTypes(container); EPMS.Implementation.TypeRegistrations.RegisterType(container); }