public ConstructorResolutionBehavior(
     IConstructorResolutionBehavior original,
     List <Func <Type, ConstructorInfo> > constructorSelectors)
 {
     this.original             = original;
     this.constructorSelectors = constructorSelectors;
 }
Пример #2
0
 public ConstructorSelectorConvention(Container container,
                                      IConstructorResolutionBehavior baseBehavior)
 {
     this.container    = container;
     this.baseBehavior = baseBehavior;
     this.constructors = new Dictionary <object, ConstructorInfo>();
 }
Пример #3
0
 /// <summary>Initializes a new instance of the <see cref="ContainerOptions"/> class.</summary>
 public ContainerOptions()
 {
     this.resolutionBehavior   = new DefaultConstructorResolutionBehavior();
     this.verificationBehavior = new DefaultConstructorVerificationBehavior();
     this.injectionBehavior    = new DefaultConstructorInjectionBehavior(() => this.Container);
     this.propertyBehavior     = new DefaultPropertySelectionBehavior();
     this.lifestyleBehavior    = new TransientLifestyleSelectionBehavior();
 }
Пример #4
0
        internal ContainerOptions(Container container)
        {
            Requires.IsNotNull(container, nameof(container));

            this.Container          = container;
            this.resolutionBehavior = new DefaultConstructorResolutionBehavior();
            this.injectionBehavior  = new DefaultDependencyInjectionBehavior(container);
            this.propertyBehavior   = new DefaultPropertySelectionBehavior();
            this.lifestyleBehavior  = new DefaultLifestyleSelectionBehavior(this);
        }
Пример #5
0
        internal ContainerOptions(Container container)
        {
            Requires.IsNotNull(container, "container");

            this.Container                 = container;
            this.resolutionBehavior        = new DefaultConstructorResolutionBehavior();
            this.injectionBehavior         = new DefaultDependencyInjectionBehavior(container);
            this.propertyBehavior          = new DefaultPropertySelectionBehavior();
            this.lifestyleBehavior         = new DefaultLifestyleSelectionBehavior(Lifestyle.Transient);
            this.batchRegistrationBehavior = new DefaultBatchRegistrationBehavior(container);
        }
Пример #6
0
 internal static string ConstructorResolutionBehaviorReturnedNull(
     IConstructorResolutionBehavior selectionBehavior, Type serviceType, Type implementationType)
 {
     return(string.Format(CultureInfo.InvariantCulture,
                          "The {0} that was registered through Container.Options.ConstructorResolutionBehavior " +
                          "returned a null reference after its GetConstructor(Type, Type) method was " +
                          "supplied with values '{1}' for serviceType and '{2}' for implementationType. " +
                          "{3}.GetConstructor implementations should never return null, but should throw " +
                          "a {4} with an expressive message instead.",
                          selectionBehavior.GetType().ToFriendlyName(),
                          serviceType.ToFriendlyName(),
                          implementationType.ToFriendlyName(),
                          typeof(IConstructorResolutionBehavior).Name,
                          typeof(ActivationException).FullName));
 }
Пример #7
0
        /// <summary>
        /// Gets the given <paramref name="implementationType"/>'s constructor that can be used by the
        /// container to create that instance.
        /// </summary>
        /// <param name="behavior">The behavior.</param>
        /// <param name="implementationType">Type of the implementation to find a suitable constructor for.</param>
        /// <returns>
        /// The <see cref="ConstructorInfo"/>. This method never returns null.
        /// </returns>
        /// <exception cref="ActivationException">Thrown when no suitable constructor could be found.</exception>
        public static ConstructorInfo GetConstructor(
            this IConstructorResolutionBehavior behavior, Type implementationType)
        {
            // NOTE: In v5, both IConstructorResolutionBehavior's and IDependencyInjectionBehavior's method
            // signatures changed (see #557). This is both a binary and code breaking change, which affects
            // anyone implementing an IConstructorResolutionBehavior. There's nothing much we can do about
            // this (since fixing #557 was more important). By adding this extension method, however, we can
            // reduce the pain for anyone using (calling) this interface. This extension method duplicates the
            // signature and behavior of the old method. This still makes the change binary incompatible, even
            // from perspective of the caller, but it would allow their code to keep compiling (in most cases).
            Requires.IsNotNull(behavior, nameof(behavior));
            Requires.IsNotNull(implementationType, nameof(implementationType));

            return(behavior.TryGetConstructor(implementationType, out string?message)
                   ?? throw BuildActivationException(behavior, implementationType, message));
        }
Пример #8
0
 internal static string ConstructorResolutionBehaviorReturnedNull(
     IConstructorResolutionBehavior selectionBehavior, Type serviceType, Type implementationType) => 
     string.Format(CultureInfo.InvariantCulture,
         "The {0} that was registered through Container.{5}.{6} returned a null reference after " +
         "its {7}(Type, Type) method was supplied with values '{1}' for serviceType and '{2}' for " +
         "implementationType. {3}.{7} implementations should never return null, but should throw " +
         "a {4} with an expressive message instead.",
         selectionBehavior.GetType().ToFriendlyName(),
         serviceType.ToFriendlyName(),
         implementationType.ToFriendlyName(),
         nameof(IConstructorResolutionBehavior),
         typeof(ActivationException).FullName,
         nameof(Container.Options),
         nameof(ContainerOptions.ConstructorResolutionBehavior),
         nameof(IConstructorResolutionBehavior.GetConstructor));
Пример #9
0
 /// <summary>
 ///   Initializes a new instance of the <see cref="SimpleInjectorContainerResolutionBehavior" /> class.
 /// </summary>
 /// <param name="originalBehavior">The original behavior.</param>
 public SimpleInjectorContainerResolutionBehavior(IConstructorResolutionBehavior originalBehavior)
 {
     _originalBehavior = originalBehavior;
 }
 /// <summary>
 ///   Initializes a new instance of the <see cref="SimpleInjectorContainerResolutionBehavior" /> class.
 /// </summary>
 /// <param name="originalBehavior">The original behavior.</param>
 public SimpleInjectorContainerResolutionBehavior(IConstructorResolutionBehavior originalBehavior)
 {
     _originalBehavior = originalBehavior;
 }
 public T4MvcControllerConstructorResolutionBehavior(IConstructorResolutionBehavior defaultBehavior)
 {
     _defaultBehavior = defaultBehavior;
 }
Пример #12
0
        internal ContainerOptions(Container container)
        {
            Requires.IsNotNull(container, nameof(container));

            this.Container = container;
            this.resolutionBehavior = new DefaultConstructorResolutionBehavior();
            this.injectionBehavior = new DefaultDependencyInjectionBehavior(container);
            this.propertyBehavior = new DefaultPropertySelectionBehavior();
            this.lifestyleBehavior = new DefaultLifestyleSelectionBehavior(Lifestyle.Transient);
        }
 public T4MvcControllerConstructorResolutionBehavior(IConstructorResolutionBehavior defaultBehavior)
 {
     _defaultBehavior = defaultBehavior;
 }
Пример #14
0
 private static ActivationException BuildActivationException(
     IConstructorResolutionBehavior behavior, Type implementationType, string?message) =>
Пример #15
0
 public SpecialConstructorResolutionBehavior(
     IConstructorResolutionBehavior original)
 {
     this.original = original;
 }
 public CacheManagerConstructorResolutionBehavior(IConstructorResolutionBehavior org)
 {
     this.org = org;
 }