コード例 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:CSF.FlexDi.Resolution.Proxies.UnregisteredServiceResolverProxy"/> class.
        /// </summary>
        /// <param name="proxiedResolver">Proxied resolver.</param>
        /// <param name="registrationResolver">Registration resolver.</param>
        /// <param name="unregisteredRegistrationProvider">Unregistered registration provider.</param>
        /// <param name="cache">The service cache.</param>
        /// <param name="registry">The service registry</param>
        public UnregisteredServiceResolverProxy(IResolver proxiedResolver,
                                                IResolvesRegistrations registrationResolver,
                                                IServiceRegistrationProvider unregisteredRegistrationProvider,
                                                ICachesResolvedServiceInstances cache,
                                                IRegistersServices registry)
            : base(proxiedResolver)
        {
            if (registry == null)
            {
                throw new ArgumentNullException(nameof(registry));
            }
            if (unregisteredRegistrationProvider == null)
            {
                throw new ArgumentNullException(nameof(unregisteredRegistrationProvider));
            }
            if (registrationResolver == null)
            {
                throw new ArgumentNullException(nameof(registrationResolver));
            }

            this.cache = cache;
            this.registrationResolver             = registrationResolver;
            this.unregisteredRegistrationProvider = unregisteredRegistrationProvider;
            this.registry = registry;
        }
コード例 #2
0
ファイル: Container.cs プロジェクト: csf-dev/FlexDi
        /// <summary>
        /// Initializes a new instance of the <see cref="T:CSF.FlexDi.Container"/> class.
        /// </summary>
        /// <remarks>
        /// <para>
        /// All of the parameters to this method are optional.  Any which are not provided will be fulfilled using
        /// default implementations.
        /// </para>
        /// <para>
        /// Of the parameters which might be used, the most useful is likely to be <paramref name="options"/> and
        /// <paramref name="parentContainer"/>.
        /// </para>
        /// </remarks>
        /// <param name="registry">An optional service registry instance.</param>
        /// <param name="cache">An optional service cache instance.</param>
        /// <param name="resolver">An optional resolver instance.</param>
        /// <param name="disposer">An optional service disposer instance.</param>
        /// <param name="options">A set of container options.</param>
        /// <param name="parentContainer">An optional parent container - indicating that this container is the child of another.</param>
        /// <param name="resolverFactory">An optional resolver factory instance.</param>
        public Container(IRegistersServices registry           = null,
                         ICachesResolvedServiceInstances cache = null,
                         IFulfilsResolutionRequests resolver   = null,
                         IDisposesOfResolvedInstances disposer = null,
                         ContainerOptions options          = null,
                         IContainer parentContainer        = null,
                         ICreatesResolvers resolverFactory = null)
        {
            disposedValue = false;

            this.parentContainer = parentContainer;

            this.options        = GetContainerOptions(options, parentContainer);
            constructorSelector = new ConstructorWithMostParametersSelector(this.options.UseNonPublicConstructors);

            this.registry      = registry ?? new Registry();
            this.cache         = cache ?? new ResolvedServiceCache();
            this.disposer      = disposer ?? new ServiceInstanceDisposer();
            this.registryStack = new RegistryStackFactory().CreateRegistryStack(this);
            this.resolver      = resolver ?? GetResolver(resolverFactory);

            this.resolver.ServiceResolved += InvokeServiceResolved;

            PerformSelfRegistrations();
        }
コード例 #3
0
ファイル: ContainerTests.cs プロジェクト: csf-dev/FlexDi
    public void Constructor_should_not_self_register_the_registry_when_options_indicate_not_to_do_so(IRegistersServices registry)
    {
      // Arrange
      var options = new ContainerOptions(selfRegisterTheRegistry: false);

      // Act
      var container = new Container(registry, options: options);

      // Assert
      Mock.Get(registry).Verify(x => x.Add(It.Is<IServiceRegistration>(r => r.ServiceType == typeof(IReceivesRegistrations))), Times.Never);
    }
コード例 #4
0
ファイル: ContainerTests.cs プロジェクト: csf-dev/FlexDi
    public void Constructor_should_self_register_the_registry_when_options_indicate_to_do_so(IRegistersServices registry)
    {
      // Arrange
      var options = new ContainerOptions(selfRegisterTheRegistry: true);
      IServiceRegistration registration = null;
      Mock.Get(registry)
          .Setup(x => x.Add(It.IsAny<IServiceRegistration>()))
          .Callback((IServiceRegistration reg) => {
        if(reg.ServiceType == typeof(IReceivesRegistrations))
          registration = reg;
      });

      // Act
      var container = new Container(registry, options: options);

      // Assert
      Mock.Get(registry).Verify(x => x.Add(It.Is<IServiceRegistration>(r => r.ServiceType == typeof(IReceivesRegistrations))), Times.Once);
      Assert.That(registration, Is.Not.Null, "Registration must not be null");
      Assert.That(registration, Is.InstanceOf<InstanceRegistration>(), "Registration is an instance registration");
      var instanceReg = (InstanceRegistration) registration;
      Assert.That(instanceReg.Implementation, Is.SameAs(container), "The self-registered resolver is the container itself");
    }