public static void ConfigureServices(IServiceCollection services, IServiceOptions options = null, IEmailService emailService = null) { options = options ?? new MosesServiceOptions(); // Register email service services.AddSingleton(options); services.AddSingleton <IEmailService, EmailService>(); }
public static void TryAddScoped(this IServiceOptions serviceOptions, Type service, Type implementationType, bool replaceExisting = false) { if (replaceExisting) { serviceOptions.RemoveAll(service); } serviceOptions.Services.TryAddScoped(service, implementationType); }
public static void TryAddSingleton(this IServiceOptions serviceOptions, Type service, Func <IServiceProvider, object> implementationFactory, bool replaceExisting = false) { if (replaceExisting) { serviceOptions.RemoveAll(service); } serviceOptions.Services.TryAddSingleton(service, implementationFactory); }
public static void TryAddTransient(this IServiceOptions serviceOptions, Type service, bool replaceExisting = false) { if (replaceExisting) { serviceOptions.RemoveAll(service); } serviceOptions.Services.TryAddTransient(service); }
public static void TryAddSingleton <TService>(this IServiceOptions serviceOptions, Func <IServiceProvider, TService> implementationFactory, bool replaceExisting = false) where TService : class { if (replaceExisting) { serviceOptions.RemoveAll <TService>(); } serviceOptions.Services.TryAddSingleton <TService>(implementationFactory); }
public static void TryAddScoped <TService>(this IServiceOptions serviceOptions, bool replaceExisting = false) where TService : class { if (replaceExisting) { serviceOptions.RemoveAll <TService>(); } serviceOptions.Services.TryAddScoped <TService>(); }
public void Add(IServiceOptions serviceOptions) { if (serviceOptions == null) { throw new ArgumentNullException(nameof(serviceOptions)); } this.services.Add(serviceOptions); }
public static void TryAddSingleton <TService, TImplementation>(this IServiceOptions serviceOptions, bool replaceExisting = false) where TService : class where TImplementation : class, TService { if (replaceExisting) { serviceOptions.RemoveAll <TService>(); } serviceOptions.Services.TryAddSingleton <TService, TImplementation>(); }
void IServiceContract.TestAGMOptions(string s, IServiceOptions options) { string additionalValue = options.ServerOptions.InvocationContext.InvocationContext.Arguments.GetValueByName( "AdditionalValue", v => v.AsString); Log($"{nameof(IServiceContract.TestAGMOptions)} {s} - invoked with {additionalValue} as additional value"); if (additionalValue == "break") { // the additional value options.ServerOptions.PostInvocationInterceptor = (context, builder) => { builder.SetIsFailed(true); builder.SetMessage("Intercepted because caller requested"); return(InterceptedActionContinuation.Break); }; return; } Log($"Normal work of {nameof(IServiceContract.TestAGMOptions)} {s}"); }
void IServiceContract.ShowClients(T42Contact[] contacts, IServiceOptions serviceOption) { Log($"Show contacts: {contacts.AsString(c => c.Name.FirstName)}"); }
public static IServiceOptions RemoveAll <T>(this IServiceOptions serviceOptions) { serviceOptions.Services.RemoveAll <T>(); return(serviceOptions); }
public static IServiceOptions RemoveAll(this IServiceOptions serviceOptions, Type serviceType) { serviceOptions.Services.RemoveAll(serviceType); return(serviceOptions); }