예제 #1
0
 public override void Setup()
 {
     base.Setup();
       _entry = ServiceEntryHelper.NewEntry();
       _instance = new SimpleService1();
       _activator = new StaticActivator(_entry, _instance);
 }
예제 #2
0
 public Activation(ServiceEntry entry, object instance, bool isBrandNew)
 {
     _entry = entry;
       _instance = instance;
       _entry.AssertIsAcceptableInstance(_instance);
       _isBrandNew = isBrandNew;
 }
예제 #3
0
 public void OnRegistration(ServiceEntry entry)
 {
     foreach (IServiceContainerListener listener in _pluginManager.AllListeners)
       {
     listener.OnRegistration(entry);
       }
 }
예제 #4
0
 public bool HasActivator(ServiceEntry entry)
 {
     using (RWLock.AsReader(_lock))
       {
     return _cache.ContainsKey(entry);
       }
 }
예제 #5
0
 public IActivator ResolveActivator(ServiceEntry entry)
 {
     using (RWLock.AsReader(_lock))
       {
     return _cache[entry];
       }
 }
예제 #6
0
 public void OnRegistration(ServiceEntry entry)
 {
     Type concreteType = entry.ConcreteType;
       if (concreteType.IsClass)
       {
       }
 }
예제 #7
0
 public DefaultActivator(IObjectFactory objectFactory, IServiceDependencyInspector serviceDependencyInspector, IServiceEntryResolver serviceEntryResolver, ServiceEntry entry)
 {
     _objectFactory = objectFactory;
       _serviceEntryResolver = serviceEntryResolver;
       _serviceDependencyInspector = serviceDependencyInspector;
       _entry = entry;
 }
 public IActivator ResolveActivator(IResolutionServices services, ServiceEntry entry)
 {
     if (!_container.CanResolve(entry.ServiceType))
       {
     return null;
       }
       return new ParentContainerActivator(_container, entry);
 }
 public IActivator CreateDefaultActivator(ServiceEntry entry)
 {
     if (!entry.HasInterceptorsApplied)
       {
     return null;
       }
       return new DynamicProxyActivator(_container, _proxyBuilder, _defaultActivatorFactory.CreateDefaultActivator(entry), entry);
 }
예제 #10
0
 public DynamicProxyActivator(IMachineContainer container, IProxyBuilder proxyBuilder, IActivator target, ServiceEntry entry)
 {
     _container = container;
       _entry = entry;
       _proxyBuilder = proxyBuilder;
       _target = target;
       _proxyGenerator = new ProxyGenerator(_proxyBuilder);
 }
 public IActivator ResolveActivator(IResolutionServices services, ServiceEntry entry)
 {
     if ((services.Flags & LookupFlags.ThrowIfUnable) == LookupFlags.ThrowIfUnable)
       {
     throw new PendingDependencyException(services.DependencyGraphTracker.BuildProgressMessage(entry));
       }
       return null;
 }
예제 #12
0
 public override void OnRegistration(ServiceEntry entry)
 {
     Type startable = typeof(IStartable);
       if (startable.IsAssignableFrom(entry.ImplementationType))
       {
     _startables.Add(entry);
       }
 }
예제 #13
0
 public object LookupOverride(ServiceEntry entry)
 {
     if (_parameters.Contains(entry.Key))
       {
     return _parameters[entry.Key];
       }
       return null;
 }
 public IActivator ResolveActivator(IResolutionServices services, ServiceEntry entry)
 {
     object value = services.Overrides.LookupOverride(entry);
       if (value == null)
       {
     return null;
       }
       return services.ActivatorFactory.CreateStaticActivator(entry, value);
 }
 public override void Setup()
 {
     base.Setup();
       _entry = ServiceEntryHelper.NewEntry();
       _objectFactory = _mocks.StrictMock<IObjectFactory>();
       _serviceDependencyInspector = _mocks.DynamicMock<IServiceDependencyInspector>();
       _serviceEntryResolver = _mocks.DynamicMock<IServiceEntryResolver>();
       _activatorFactory = new DefaultActivatorFactory(_objectFactory, _serviceDependencyInspector, _serviceEntryResolver);
 }
예제 #16
0
 public IDisposable Push(ServiceEntry entry)
 {
     if (_progress.Contains(entry))
       {
     throw new CircularDependencyException(BuildProgressMessage(entry));
       }
       _progress.Push(entry);
       return this;
 }
예제 #17
0
 public void Add(ServiceEntry entry)
 {
     using (RWLock.AsWriter(_lock))
       {
     _log.Info("Adding: " + entry);
     _map[entry.ServiceType] = entry;
     _registrationOrder.Add(entry.ServiceType);
     _listenerInvoker.OnRegistration(entry);
       }
 }
예제 #18
0
 public object LookupOverride(ServiceEntry entry)
 {
     foreach (object value in _objects)
       {
     if (entry.ServiceType.IsAssignableFrom(value.GetType()))
     {
       return value;
     }
       }
       return null;
 }
예제 #19
0
 public static string BuildMessage(ServiceEntry target, Stack<ServiceEntry> progress)
 {
     StringBuilder sb = new StringBuilder();
       sb.AppendLine("Error resolving: " + target);
       foreach (ServiceEntry entry in progress)
       {
     sb.AppendLine(entry.ToString());
       }
       sb.AppendLine();
       sb.AppendLine("");
       return sb.ToString();
 }
예제 #20
0
 public void AddActivator(ServiceEntry entry, IActivator activator)
 {
     using (RWLock.AsWriter(_lock))
       {
     if (_cache.ContainsKey(entry))
     {
       throw new ServiceContainerException("Multiple activators for one entry!");
     }
     _log.Info("Adding: " + entry + " " + activator);
     _cache[entry] = activator;
       }
 }
 public virtual IActivator ResolveActivator(IResolutionServices services, ServiceEntry entry)
 {
     if (!services.ActivatorStore.HasActivator(entry))
       {
     return null;
       }
       IActivator activator = services.ActivatorStore.ResolveActivator(entry);
       if (activator.CanActivate(services))
       {
     return activator;
       }
       throw new ServiceResolutionException("Unable to activate: " + entry);
 }
예제 #22
0
 public ServiceEntry ToServiceEntry(IResolutionServices services)
 {
     if (_entry == null)
       {
     _entry = _serviceGraph.Lookup(_type, services.Flags);
     if (_entry != null)
     {
       return _entry;
     }
     return _serviceEntryFactory.CreateServiceEntry(_type, LifestyleType.Override);
       }
       return _entry;
 }
예제 #23
0
 private static void CreateActivatorForEntryIfNecessary(IResolutionServices services, ServiceEntry entry)
 {
     if (!services.ActivatorStore.HasActivator(entry))
       {
     entry.Lock.UpgradeToWriterLock();
     if (services.ActivatorStore.HasActivator(entry))
     {
       return;
     }
     ILifestyle lifestyle = services.LifestyleFactory.CreateLifestyle(entry);
     services.ActivatorStore.AddActivator(entry, lifestyle);
       }
 }
예제 #24
0
 protected virtual IInterceptor[] FindInterceptors(ServiceEntry entry)
 {
     List<IInterceptor> interceptors = new List<IInterceptor>();
       foreach (InterceptorApplication interceptor in entry.Interceptors)
       {
     try
     {
       interceptors.Add((IInterceptor)_container.Resolve.Object(interceptor.InterceptorType));
     }
     catch (Exception error)
     {
       throw new DynamicProxyException("Error resolving Interceptor: " + interceptor, error);
     }
       }
       return interceptors.ToArray();
 }
예제 #25
0
 public ILifestyle CreateLifestyle(ServiceEntry entry)
 {
     switch (entry.LifestyleType)
       {
     case LifestyleType.Singleton:
       return CreateSingletonLifestyle(entry);
     case LifestyleType.Transient:
       return CreateTransientLifestyle(entry);
     case LifestyleType.PerWebRequest:
       return CreateWebRequestLifestyle(entry);
     case LifestyleType.PerThread:
       return CreatePerThreadLifestyle(entry);
     case LifestyleType.PerWebRequestAndPerThreadHybrid:
       return CreatePerWebRequestAndPerThreadHybridLifestyle(entry);
       }
       throw new ArgumentException("entry");
 }
 public IActivator ResolveActivator(IResolutionServices services, ServiceEntry entry)
 {
     if (FactoryHelper.IsFactoryType(entry.ServiceType))
       {
     return null;
       }
       Type factoryType = FactoryHelper.CreateFactoryType(entry.ServiceType);
       if (!_container.CanResolve(factoryType))
       {
     return null;
       }
       lock (_lock)
       {
     if (services.ActivatorStore.HasActivator(entry))
     {
       return services.ActivatorStore.ResolveActivator(entry);
     }
     IActivator activator = new FactoriesActivator(_container, entry);
     services.ActivatorStore.AddActivator(entry, activator);
     services.ServiceGraph.Add(entry);
     return activator;
       }
 }
예제 #27
0
 public ResolvedServiceEntry(ServiceEntry entry, IActivator activator, IObjectInstances objectInstances)
 {
     _entry = entry;
       _objectInstances = objectInstances;
       _activator = activator;
 }
예제 #28
0
 public TransientLifestyle(IActivatorFactory activatorFactory, ServiceEntry serviceEntry)
 {
     _activatorFactory = activatorFactory;
       _entry = serviceEntry;
 }
예제 #29
0
 public ParentContainerActivator(IMachineContainer container, ServiceEntry entry)
 {
     _container = container;
       _entry = entry;
 }
예제 #30
0
 public StaticActivator(ServiceEntry entry, object instance)
 {
     _activation = new Activation(entry, instance, false);
 }