Exemplo n.º 1
0
        /// <summary>
        /// ApplyChanges
        /// </summary>
        private static void ApplyChange(Lazy <TIService> service, ISetupDescriptor changeDescriptor)
        {
            if (service == null)
            {
                throw new ArgumentNullException("service");
            }
            if (!service.IsValueCreated)
            {
                throw new InvalidOperationException("Service value has not been created yet.");
            }
            var registration = Registration;

            if (registration == null)
            {
                throw new NullReferenceException("Registration");
            }
            var onChange = registration.OnChange;

            if (onChange != null)
            {
                onChange(service.Value, changeDescriptor);
            }
        }
Exemplo n.º 2
0
        public static Lazy <TIService> MakeByProviderProtected(Func <TIService> provider, ISetupDescriptor setupDescriptor)
        {
            if (provider == null)
            {
                throw new ArgumentNullException("provider");
            }
            var lazy = new Lazy <TIService>(provider);

            GetSetupDescriptorProtected(lazy, setupDescriptor);
            return(lazy);
        }
Exemplo n.º 3
0
        protected static ISetupDescriptor GetSetupDescriptorProtected(Lazy <TIService> service, ISetupDescriptor firstDescriptor)
        {
            if (service == null)
            {
                throw new ArgumentNullException("service");
            }
            if (service.IsValueCreated)
            {
                return(new SetupDescriptor(Registration, d => ApplyChange(service, d)));
            }
            ISetupDescriptor descriptor;

            if (_setupDescriptors.TryGetValue(service, out descriptor))
            {
                if (firstDescriptor == null)
                {
                    return(descriptor);
                }
                throw new InvalidOperationException(string.Format(Local.RedefineSetupDescriptorA, service.ToString()));
            }
            lock (_lock)
                if (!_setupDescriptors.TryGetValue(service, out descriptor))
                {
                    descriptor = (firstDescriptor ?? new SetupDescriptor(Registration, null));
                    _setupDescriptors.Add(service, descriptor);
                    service.HookValueFactory(valueFactory => ApplySetup(service, LazyValue = valueFactory()));
                }
            return(descriptor);
        }
 /// <summary>
 /// Sets the provider.
 /// </summary>
 /// <param name="provider">The provider.</param>
 /// <param name="setupDescriptor">The setup descriptor.</param>
 /// <returns></returns>
 public static Lazy <IServiceLog> SetProvider(Func <IServiceLog> provider, ISetupDescriptor setupDescriptor)
 {
     return(Lazy = MakeByProviderProtected(provider, setupDescriptor));
 }
Exemplo n.º 5
0
 /// <summary>
 /// Sets the provider.
 /// </summary>
 /// <param name="provider">The provider.</param>
 /// <param name="setupDescriptor">The setup descriptor.</param>
 /// <returns></returns>
 public static Lazy <IPlatformWeb> SetProvider(Func <IPlatformWeb> provider, ISetupDescriptor setupDescriptor)
 {
     return(Lazy = MakeByProviderProtected(provider, setupDescriptor));
 }
 /// <summary>
 /// Sets the provider.
 /// </summary>
 /// <param name="provider">The provider.</param>
 /// <param name="setupDescriptor">The setup descriptor.</param>
 /// <returns></returns>
 public static Lazy <IEventSource> SetProvider(Func <IEventSource> provider, ISetupDescriptor setupDescriptor)
 {
     return(Lazy = MakeByProviderProtected(provider, setupDescriptor));
 }
 /// <summary>
 /// Makes the by provider.
 /// </summary>
 /// <param name="provider">The provider.</param>
 /// <param name="setupDescriptor">The setup descriptor.</param>
 /// <returns></returns>
 public static Lazy<IServiceBus> MakeByProvider(Func<IServiceBus> provider, ISetupDescriptor setupDescriptor) { return MakeByProviderProtected(provider, setupDescriptor); }
Exemplo n.º 8
0
 /// <summary>
 /// Makes the by provider.
 /// </summary>
 /// <param name="provider">The provider.</param>
 /// <param name="setupDescriptor">The setup descriptor.</param>
 /// <returns></returns>
 public static Lazy <IServiceCache> MakeByProvider(Func <IServiceCache> provider, ISetupDescriptor setupDescriptor)
 {
     return(MakeByProviderProtected(provider, setupDescriptor));
 }