/// <summary> /// Updates the default components. /// <para /> /// This method should be called when any of the factory methods has been changed. /// </summary> /// <exception cref="System.Exception">The method fails to create the <see cref="IServiceLocator"/> using the factory.</exception> public static void UpdateDefaultComponents() { Log.Info("Updating default components"); // Don't initialize the first service locator (we are still loading assemblies at that time) bool initializeServiceLocator = (_defaultServiceLocator != null); var serviceLocator = IoCFactory.CreateServiceLocator(initializeServiceLocator); lock (_lockObject) { DefaultServiceLocator = serviceLocator; DefaultDependencyResolver = serviceLocator.ResolveType <IDependencyResolver>(); DefaultTypeFactory = serviceLocator.ResolveType <ITypeFactory>(); } }
/// <summary> /// Initializes a new instance of the <see cref="ServiceLocator"/> class. /// </summary> public ServiceLocator() { // Must be registered first, already resolved by TypeFactory RegisterInstance(typeof(IServiceLocator), this); RegisterInstance(typeof(IDependencyResolver), IoCFactory.CreateDependencyResolverFunc(this)); _typeFactory = IoCFactory.CreateTypeFactoryFunc(this); RegisterInstance(typeof(ITypeFactory), _typeFactory); _autoRegistrationManager = new ServiceLocatorAutoRegistrationManager(this); IgnoreRuntimeIncorrectUsageOfRegisterAttribute = true; CanResolveNonAbstractTypesWithoutRegistration = true; // Register default implementations // TODO: Enable for CTL-272 //RegisterType(typeof(ICollection<>), typeof(Collection<>)); //RegisterType(typeof(IEnumerable<>), typeof(List<>)); //RegisterType(typeof(IList<>), typeof(List<>)); }