internal HarshProvisionerMetadata(Type type)
            : base(type)
        {
            if (!HarshProvisionerBaseTypeInfo.IsAssignableFrom(ObjectTypeInfo))
            {
                throw Logger.Fatal.ArgumentTypeNotAssignableTo(
                          nameof(type),
                          type,
                          HarshProvisionerBaseTypeInfo.AsType()
                          );
            }

            ParameterSets = new ParameterSetBuilder(this, ProvisioningDefaultValuePolicy.Instance)
                            .Build()
                            .ToImmutableArray();

            ContextType = ObjectType.GetRuntimeBaseTypeChain()
                          .FirstOrDefault(t =>
                                          t.IsGenericType &&
                                          t.GetGenericTypeDefinition() == typeof(HarshProvisionerBase <>)
                                          )?
                          .GenericTypeArguments
                          .First();

            ParameterProperties = Parameters
                                  .Select(p => p.PropertyAccessor)
                                  .Distinct()
                                  .ToImmutableArray();

            DefaultParameterSet = ParameterSets.Single(set => set.IsDefault);

            DefaultFromContextPropertyBinder = new DefaultFromContextPropertyBinder(
                ReadableWritableInstancePropertiesWithSingle <DefaultFromContextAttribute>(inherit: true)
                .Select(t => new DefaultFromContextProperty(t.Item1, t.Item2))
                );

            ParametersMandatoryWhenCreating =
                Parameters
                .Where(p => p.IsDefined(typeof(MandatoryWhenCreatingAttribute), inherit: true))
                .ToImmutableHashSet();

            ResolvedPropertyBinder = new ResolvedPropertyBinder(
                ReadableWritableInstanceProperties
                .Where(ResolvedPropertyTypeInfo.IsResolveType)
                );

            UnprovisionDeletesUserData = GetDeletesUserData("OnUnprovisioningAsync");
        }
Example #2
0
        protected T Bind <T>(T value, Func <IResolveContext> contextFactory)
        {
            if (value == null)
            {
                throw Logger.Fatal.ArgumentNull(nameof(value));
            }

            var binder = new ResolvedPropertyBinder(typeof(Holder <T>));
            var holder = new Holder <T>()
            {
                Value = value
            };

            binder.Bind(
                holder,
                contextFactory ?? ResolveContextFactory
                );

            return(holder.Value);
        }
 public ResolvedPropertyBinding(ITestOutputHelper output) : base(output)
 {
     Binder = new ResolvedPropertyBinder(GetType());
 }