public override void Setup() { base.Setup(); _entry = ServiceEntryHelper.NewEntry(); _instance = new SimpleService1(); _activator = new StaticActivator(_entry, _instance); }
public Activation(ServiceEntry entry, object instance, bool isBrandNew) { _entry = entry; _instance = instance; _entry.AssertIsAcceptableInstance(_instance); _isBrandNew = isBrandNew; }
public void OnRegistration(ServiceEntry entry) { foreach (IServiceContainerListener listener in _pluginManager.AllListeners) { listener.OnRegistration(entry); } }
public bool HasActivator(ServiceEntry entry) { using (RWLock.AsReader(_lock)) { return _cache.ContainsKey(entry); } }
public IActivator ResolveActivator(ServiceEntry entry) { using (RWLock.AsReader(_lock)) { return _cache[entry]; } }
public void OnRegistration(ServiceEntry entry) { Type concreteType = entry.ConcreteType; if (concreteType.IsClass) { } }
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); }
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; }
public override void OnRegistration(ServiceEntry entry) { Type startable = typeof(IStartable); if (startable.IsAssignableFrom(entry.ImplementationType)) { _startables.Add(entry); } }
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); }
public IDisposable Push(ServiceEntry entry) { if (_progress.Contains(entry)) { throw new CircularDependencyException(BuildProgressMessage(entry)); } _progress.Push(entry); return this; }
public void Add(ServiceEntry entry) { using (RWLock.AsWriter(_lock)) { _log.Info("Adding: " + entry); _map[entry.ServiceType] = entry; _registrationOrder.Add(entry.ServiceType); _listenerInvoker.OnRegistration(entry); } }
public object LookupOverride(ServiceEntry entry) { foreach (object value in _objects) { if (entry.ServiceType.IsAssignableFrom(value.GetType())) { return value; } } return null; }
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(); }
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); }
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; }
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); } }
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(); }
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; } }
public ResolvedServiceEntry(ServiceEntry entry, IActivator activator, IObjectInstances objectInstances) { _entry = entry; _objectInstances = objectInstances; _activator = activator; }
public TransientLifestyle(IActivatorFactory activatorFactory, ServiceEntry serviceEntry) { _activatorFactory = activatorFactory; _entry = serviceEntry; }
public ParentContainerActivator(IMachineContainer container, ServiceEntry entry) { _container = container; _entry = entry; }
public StaticActivator(ServiceEntry entry, object instance) { _activation = new Activation(entry, instance, false); }