Пример #1
0
        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>();
        }
Пример #2
0
 public static void TryAddScoped(this IServiceOptions serviceOptions, Type service, Type implementationType, bool replaceExisting = false)
 {
     if (replaceExisting)
     {
         serviceOptions.RemoveAll(service);
     }
     serviceOptions.Services.TryAddScoped(service, implementationType);
 }
Пример #3
0
 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);
 }
Пример #4
0
 public static void TryAddTransient(this IServiceOptions serviceOptions, Type service, bool replaceExisting = false)
 {
     if (replaceExisting)
     {
         serviceOptions.RemoveAll(service);
     }
     serviceOptions.Services.TryAddTransient(service);
 }
Пример #5
0
 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);
 }
Пример #6
0
 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);
        }
Пример #8
0
 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>();
 }
Пример #9
0
        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}");
        }
Пример #10
0
 void IServiceContract.ShowClients(T42Contact[] contacts, IServiceOptions serviceOption)
 {
     Log($"Show contacts: {contacts.AsString(c => c.Name.FirstName)}");
 }
Пример #11
0
 public static IServiceOptions RemoveAll <T>(this IServiceOptions serviceOptions)
 {
     serviceOptions.Services.RemoveAll <T>();
     return(serviceOptions);
 }
Пример #12
0
 public static IServiceOptions RemoveAll(this IServiceOptions serviceOptions, Type serviceType)
 {
     serviceOptions.Services.RemoveAll(serviceType);
     return(serviceOptions);
 }