/// <summary> /// Register the type with the given factory to the container. /// </summary> /// <typeparam name="TService">The type to register the implementation as</typeparam> /// <param name="providedValue">Parameter to obtain a provided value.</param> /// <param name="factory">The factory method to produce the service.</param> /// <returns>The current <see cref="AutoSubstituteBuilder"/>.</returns> public AutoSubstituteBuilder Provide <TService>(out IProvidedValue <TService> providedValue, Func <IComponentContext, TService> factory) { var key = new object(); _builder.Register(factory) .Keyed <TService>(key) .As <TService>() .InstancePerLifetimeScope(); providedValue = CreateProvidedValue <TService>(c => c.ResolveKeyed <TService>(key)); return(this); }
/// <summary> /// Allows a way to access the services being configured that the container will provide. /// </summary> /// <param name="service">Parameter to obtain the substituted value.</param> /// <returns></returns> public SubstituteForBuilder2 <TService> Provide(out IProvidedValue <TService> service) { var provided = new ProvidedValue <TService>(); _builder.ConfigureBuilder(b => { b.RegisterBuildCallback(scope => { provided.Value = scope.Resolve <TService>(); }); }); service = provided; return(this); }
/// <summary> /// Register the specified implementation type to the container as the specified service type with the given parameterst. /// </summary> /// <typeparam name="TService">The type to register the implementation as</typeparam> /// <typeparam name="TImplementation">The implementation type</typeparam> /// <param name="providedValue">Parameter to obtain a provided value.</param> /// <param name="parameters">Optional constructor parameters</param> /// <returns>The current <see cref="AutoSubstituteBuilder"/>.</returns> public AutoSubstituteBuilder Provide <TService, TImplementation>(out IProvidedValue <TService> providedValue, params Parameter[] parameters) { var key = new object(); _builder.RegisterType <TImplementation>() .Keyed <TService>(key) .As <TService>() .WithParameters(parameters) .InstancePerLifetimeScope(); providedValue = CreateProvidedValue <TService>(c => c.ResolveKeyed <TService>(key)); SkipMockIfNeeded <TService>(); return(this); }
/// <summary> /// Register the specified implementation type to the container as itself with the given parameters. /// </summary> /// <typeparam name="TService">The type to register the implementation as</typeparam> /// <typeparam name="TImplementation">The implementation type</typeparam> /// <param name="providedValue">Parameter to obtain a provided value.</param> /// <param name="parameters">Optional constructor parameters</param> /// <returns>The current <see cref="AutoSubstituteBuilder"/>.</returns> public AutoSubstituteBuilder Provide <TService>(out IProvidedValue <TService> providedValue, params Parameter[] parameters) => Provide <TService, TService>(out providedValue, parameters);