コード例 #1
0
        public BankRegistration BankRegistration(
            string name,
            Guid bankId,
            string softwareStatementProfileId,
            RegistrationScope registrationScope)
        {
            string?BankRegistrationResponsePath(RegistrationScope apiSet)
            {
                string bankRegistrationResponsesPath = AppContext.BaseDirectory; // default value

                CustomBankRegistrationResponsesPath(ref bankRegistrationResponsesPath);
                string filePath = Path.Combine(
                    bankRegistrationResponsesPath,
                    $"{RegistrationScopeApiSetHelper.AbbreviatedName(apiSet)}_{BankProfileEnum.ToString()}.json");

                return(File.Exists(filePath) ? filePath : null);
            }

            return(BankRegistrationAdjustments.Invoke(
                       new BankRegistration
            {
                BankId = bankId,
                AllowMultipleRegistrations = true,
                SoftwareStatementProfileId = softwareStatementProfileId,
                RegistrationScope = registrationScope,
                BankRegistrationResponseFileName = BankRegistrationResponsePath(registrationScope),
                Name = name
            },
                       registrationScope));
        }
コード例 #2
0
 public InjectAttribute(
     RegistrationScope scope = RegistrationScope.Transient,
     RegistrationType type   = RegistrationType.AsImplementedInterfaces)
 {
     Scope = scope;
     Type  = type;
 }
コード例 #3
0
        /// <summary>
        /// Registers the default mediator.
        /// </summary>
        /// <param name="kernel">            The service registrar. </param>
        /// <param name="registrationScope"> The registration scope. </param>
        /// <returns> The <see cref="IKernel" />. </returns>
        public static IKernel RegisterDefaultMediator(this IKernel kernel, RegistrationScope registrationScope)
        {
            kernel
            .GetServiceRegistrar()
            .RegisterDefaultMediator(registrationScope);

            return(kernel);
        }
コード例 #4
0
        /// <summary>
        /// Registers all request handlers.
        /// </summary>
        /// <param name="kernel">            The service registrar. </param>
        /// <param name="registrationScope"> The registration scope. </param>
        /// <param name="assembliesToScan">  The assemblies to scan. </param>
        /// <returns> The <see cref="IKernel" />. </returns>
        public static IKernel RegisterAllRequestHandlers(this IKernel kernel, RegistrationScope registrationScope, IEnumerable <Assembly> assembliesToScan)
        {
            kernel
            .GetServiceRegistrar()
            .RegisterAllRequestHandlers(registrationScope, assembliesToScan);

            return(kernel);
        }
コード例 #5
0
 /// <summary>
 ///     Initializing an instance of the class, with providing the filename
 ///     of the starting executable file, a <paramref name="name" /> for the
 ///     program, specifying an <paramref name="scope" /> and explicitly
 ///     specifying the dependency on administrator privileges. Using this
 ///     constructor you can specify a custom string to be used as the
 ///     startup indicator. Make sure that there is no other string similar
 ///     to this string in your expected command line arguments to conflict
 ///     with it.
 /// </summary>
 /// <param name="applicationImage">
 ///     The address of the executable file of the application
 /// </param>
 /// <param name="name">
 ///     A unique name for the rule as an alias for the program
 /// </param>
 /// <param name="scope">
 ///     Scope in which startup rule should be created or managed
 /// </param>
 /// <param name="needsAdminPrivileges">
 ///     Set to True if the program should be executed with administrator's
 ///     rights
 /// </param>
 /// <param name="startupSpecialArgument">
 ///     A special string to send to the program when started and to detect
 ///     the automatic startup
 /// </param>
 /// <exception cref="ArgumentException">Bad argument value.</exception>
 public StartupManager(string applicationImage, string name, RegistrationScope scope, bool needsAdminPrivileges,
                       string startupSpecialArgument)
     : this(
         applicationImage, name, scope, needsAdminPrivileges,
         Environment.OSVersion.Version.Major >= 6 &&
         (needsAdminPrivileges || Environment.OSVersion.Version.Minor >= 2)
             ? StartupProviders.Task
             : StartupProviders.Registry, startupSpecialArgument)
 {
 }
コード例 #6
0
        private static RegistrationScope Restricted(this RegistrationScope targetedScope, RegistrationScope limitedScope)
        {
            if (targetedScope == RegistrationScope.Transient || limitedScope == RegistrationScope.Transient)
            {
                return(RegistrationScope.Transient);
            }

            if (targetedScope == RegistrationScope.Scoped || limitedScope == RegistrationScope.Scoped)
            {
                return(RegistrationScope.Scoped);
            }

            return(targetedScope);
        }
コード例 #7
0
 /// <summary>
 ///     Initializing an instance of the class, with providing the filename
 ///     of the starting executable file, a <paramref name="name" /> for the
 ///     program, specifying an <paramref name="scope" /> and explicitly
 ///     specifying the dependency on administrator privileges. Using this
 ///     constructor you can specify a custom string to be used as the
 ///     startup indicator. Make sure that there is no other string similar
 ///     to this string in your expected command line arguments to conflict
 ///     with it.
 /// </summary>
 /// <param name="applicationImage">
 ///     The address of the executable file of the application
 /// </param>
 /// <param name="name">
 ///     A unique name for the rule as an alias for the program
 /// </param>
 /// <param name="scope">
 ///     Scope in which startup rule should be created or managed
 /// </param>
 /// <param name="needsAdminPrivileges">
 ///     Set to True if the program should be executed with administrator's
 ///     rights
 /// </param>
 /// <param name="provider">
 ///     Method that is expected to be used for registering the program
 ///     startup
 /// </param>
 /// <param name="startupSpecialArgument">
 ///     A special string to send to the program when started and to detect
 ///     the automatic startup
 /// </param>
 /// <exception cref="ArgumentException">Bad argument value.</exception>
 public StartupManager(string applicationImage, string name, RegistrationScope scope, bool needsAdminPrivileges,
                       StartupProviders provider, string startupSpecialArgument)
 {
     if (!File.Exists(applicationImage))
     {
         throw new ArgumentException("File doesn't exist.", nameof(applicationImage));
     }
     if (string.IsNullOrEmpty(name.Trim()))
     {
         throw new ArgumentException("Bad name for application.", nameof(name));
     }
     if (string.IsNullOrEmpty(startupSpecialArgument.Trim()) || IsAnyWhitespaceIn(startupSpecialArgument.Trim()))
     {
         throw new ArgumentException("Bad string provided as special argument for startup detection.",
                                     nameof(startupSpecialArgument));
     }
     ApplicationImage = applicationImage;
     WorkingDirectory = Path.GetDirectoryName(applicationImage);
     Name             = name.Trim();
     NeedsAdministrativePrivileges = needsAdminPrivileges;
     RegistrationScope             = scope;
     StartupSpecialArgument        = startupSpecialArgument.Trim();
     Provider = provider;
 }
コード例 #8
0
 /// <summary>
 ///     Initializing an instance of the class, with providing a
 ///     <paramref name="name" /> for the program, specifying an
 ///     <paramref name="scope" /> and explicitly specifying the dependency on
 ///     administrator privileges.
 /// </summary>
 /// <param name="name">
 ///     A unique name for the rule as an alias for the program
 /// </param>
 /// <param name="scope">
 ///     Scope in which startup rule should be created or managed
 /// </param>
 /// <param name="needsAdminPrivileges">
 ///     Set to True if the program should be executed with administrator's
 ///     rights
 /// </param>
 public StartupManager(string name, RegistrationScope scope, bool needsAdminPrivileges)
     : this(Assembly.GetEntryAssembly().Location, name, scope, needsAdminPrivileges)
 {
     FixWorkingDirectory();
 }
コード例 #9
0
        private static IServiceRegistrar Register(this IServiceRegistrar serviceRegistrar, Type serviceType, Type implementationType, RegistrationScope registrationScope)
        {
            switch (registrationScope)
            {
            case RegistrationScope.Singleton:
                return(serviceRegistrar.AddSingleton(serviceType, implementationType));

            case RegistrationScope.Scoped:
                return(serviceRegistrar.AddScoped(serviceType, implementationType));

            case RegistrationScope.Transient:
                return(serviceRegistrar.AddTransient(serviceType, implementationType));

            default:
                break;
            }

            return(serviceRegistrar);
        }
コード例 #10
0
 private static IServiceRegistrar Register <TService, TImplementation>(this IServiceRegistrar serviceRegistrar, RegistrationScope registrationScope) where TImplementation : TService
 => serviceRegistrar.Register(typeof(TService), typeof(TImplementation), registrationScope);
コード例 #11
0
        /// <summary>
        /// Helper method use to differentiate behavior between request handlers and notification
        /// handlers. Request handlers should only be added once (so set addIfAlreadyExists to false)
        /// Notification handlers should all be added (set addIfAlreadyExists to true)
        /// </summary>
        /// <param name="serviceRegistrar">      </param>
        /// <param name="registrationScope">     </param>
        /// <param name="openRequestInterface">  </param>
        /// <param name="assembliesToScan">      </param>
        /// <param name="addIfAlreadyExists">    </param>
        private static IServiceRegistrar ConnectImplementationsToTypesClosing(this IServiceRegistrar serviceRegistrar,
                                                                              RegistrationScope registrationScope,
                                                                              Type openRequestInterface,
                                                                              IEnumerable <Assembly> assembliesToScan,
                                                                              bool addIfAlreadyExists)
        {
            if (!assembliesToScan.Any())
            {
                assembliesToScan = AppDomain.CurrentDomain.GetAssemblies();
            }

            var concretions = new List <Type>();
            var interfaces  = new List <Type>();

            foreach (var type in assembliesToScan.SelectMany(a => a.DefinedTypes).Where(t => !t.IsOpenGeneric()))
            {
                var interfaceTypes = Enumerable.ToArray <Type>(type.FindInterfacesThatClose(openRequestInterface));
                if (!interfaceTypes.Any())
                {
                    continue;
                }

                if (type.IsConcrete())
                {
                    concretions.Add(type);
                }

                foreach (var interfaceType in interfaceTypes)
                {
                    interfaces.Fill(interfaceType);
                }
            }

            foreach (var @interface in interfaces)
            {
                var exactMatches = concretions.Where(x => x.CanBeCastTo(@interface)).ToList();
                if (addIfAlreadyExists)
                {
                    foreach (var type in exactMatches)
                    {
                        serviceRegistrar.Register(@interface, type, registrationScope);
                    }
                }
                else
                {
                    if (exactMatches.Count > 1)
                    {
                        exactMatches.RemoveAll(m => !IsMatchingWithInterface(m, @interface));
                    }

                    foreach (var type in exactMatches)
                    {
                        serviceRegistrar.Register(@interface, type, registrationScope);
                    }
                }

                if ([email protected]())
                {
                    serviceRegistrar.AddConcretionsThatCouldBeClosed(registrationScope, @interface, concretions);
                }
            }

            return(serviceRegistrar);
        }
コード例 #12
0
        /// <summary>
        /// Registers the default mediator.
        /// </summary>
        /// <param name="services">          The service registrar. </param>
        /// <param name="registrationScope"> The registration scope. </param>
        /// <returns> The <see cref="ServiceCollection" />. </returns>
        public static ServiceCollection RegisterDefaultMediator(this ServiceCollection services, RegistrationScope registrationScope)
        {
            services
            .GetServiceRegistrar()
            .RegisterDefaultMediator(registrationScope);

            return(services);
        }
コード例 #13
0
 /// <summary>
 /// Registers all request handlers.
 /// </summary>
 /// <param name="services">          The service registrar. </param>
 /// <param name="registrationScope"> The registration scope. </param>
 /// <param name="assembliesToScan">  The assemblies to scan. </param>
 /// <returns> The <see cref="ServiceCollection" />. </returns>
 public static ServiceCollection RegisterAllRequestHandlers(this ServiceCollection services, RegistrationScope registrationScope, params Assembly[] assembliesToScan)
 => services.RegisterAllRequestHandlers(registrationScope, assembliesToScan.AsEnumerable());
コード例 #14
0
 /// <summary>
 /// Registers all request handlers.
 /// </summary>
 /// <param name="kernel">            The service registrar. </param>
 /// <param name="registrationScope"> The registration scope. </param>
 /// <param name="assembliesToScan">  The assemblies to scan. </param>
 /// <returns> The <see cref="IKernel" />. </returns>
 public static IKernel RegisterAllRequestHandlers(this IKernel kernel, RegistrationScope registrationScope, params Assembly[] assembliesToScan)
 => kernel.RegisterAllRequestHandlers(registrationScope, assembliesToScan.AsEnumerable());
コード例 #15
0
 /// <summary>
 /// Registers the default mediator.
 /// </summary>
 /// <param name="serviceRegistrar">  The service registrar. </param>
 /// <param name="registrationScope"> The registration scope. </param>
 /// <returns> The <see cref="IServiceRegistrar" /> </returns>
 public static IServiceRegistrar RegisterDefaultMediator(this IServiceRegistrar serviceRegistrar, RegistrationScope registrationScope)
 {
     registrationScope = RegistrationScope.Singleton.Restricted(registrationScope);
     return(serviceRegistrar
            .Register <IMediator, Mediator>(registrationScope));
 }
コード例 #16
0
        /// <summary>
        /// Registers all request handlers.
        /// </summary>
        /// <param name="serviceRegistrar">  The service registrar. </param>
        /// <param name="registrationScope"> The registration scope. </param>
        /// <param name="assembliesToScan">  The assemblies to scan. </param>
        /// <returns>  </returns>
        public static IServiceRegistrar RegisterAllRequestHandlers(this IServiceRegistrar serviceRegistrar, RegistrationScope registrationScope, IEnumerable <Assembly> assembliesToScan)
        {
            assembliesToScan  = (assembliesToScan as Assembly[] ?? assembliesToScan).Distinct().ToArray();
            registrationScope = RegistrationScope.Singleton.Restricted(registrationScope);

            return(serviceRegistrar
                   .ConnectImplementationsToTypesClosing(registrationScope, typeof(IRequestHandler <,>), assembliesToScan, false));
        }
コード例 #17
0
 /// <summary>
 ///     Simplest form for initializing an instance of the class, with
 ///     providing a <paramref name="name" /> for the program and specifying
 ///     an <paramref name="scope" />.
 /// </summary>
 /// <param name="name">
 ///     A unique name for the rule as an alias for the program
 /// </param>
 /// <param name="scope">
 ///     Scope in which startup rule should be created or managed
 /// </param>
 public StartupManager(string name, RegistrationScope scope)
     : this(name, scope, IsElevated)
 {
 }
コード例 #18
0
 /// <summary>
 /// Registers all request handlers.
 /// </summary>
 /// <param name="serviceRegistrar">  The service registrar. </param>
 /// <param name="registrationScope"> The registration scope. </param>
 /// <param name="assembliesToScan">  The assemblies to scan. </param>
 /// <returns>  </returns>
 public static IServiceRegistrar RegisterAllRequestHandlers(this IServiceRegistrar serviceRegistrar, RegistrationScope registrationScope, params Assembly[] assembliesToScan)
 => serviceRegistrar.RegisterAllRequestHandlers(registrationScope, assembliesToScan.AsEnumerable());
コード例 #19
0
 /// <summary>
 ///     Initializing an instance of the class, with providing the filename
 ///     of the starting executable file, a <paramref name="name" /> for the
 ///     program, specifying an <paramref name="scope" /> and explicitly
 ///     specifying the dependency on administrator privileges.
 /// </summary>
 /// <param name="applicationImage">
 ///     The address of the executable file of the application
 /// </param>
 /// <param name="name">
 ///     A unique name for the rule as an alias for the program
 /// </param>
 /// <param name="scope">
 ///     Scope in which startup rule should be created or managed
 /// </param>
 /// <param name="needsAdminPrivileges">
 ///     Set to True if the program should be executed with administrator's
 ///     rights
 /// </param>
 public StartupManager(string applicationImage, string name, RegistrationScope scope, bool needsAdminPrivileges)
     :
     this(applicationImage, name, scope, needsAdminPrivileges, "--startup")
 {
 }
コード例 #20
0
 private static void AddConcretionsThatCouldBeClosed(this IServiceRegistrar serviceRegistrar, RegistrationScope registrationScope, Type @interface, List <Type> concretions)
 {
     foreach (var type in concretions
              .Where(x => x.IsOpenGeneric() && x.CouldCloseTo(@interface)))
     {
         try
         {
             serviceRegistrar.Register(@interface, type.MakeGenericType(@interface.GenericTypeArguments), registrationScope);
         }
         catch (Exception)
         {
         }
     }
 }
コード例 #21
0
        /// <summary>
        /// Registers all request handlers.
        /// </summary>
        /// <param name="services">          The service registrar. </param>
        /// <param name="registrationScope"> The registration scope. </param>
        /// <param name="assembliesToScan">  The assemblies to scan. </param>
        /// <returns> The <see cref="ServiceCollection" />. </returns>
        public static ServiceCollection RegisterAllRequestHandlers(this ServiceCollection services, RegistrationScope registrationScope, IEnumerable <Assembly> assembliesToScan)
        {
            services
            .GetServiceRegistrar()
            .RegisterAllRequestHandlers(registrationScope, assembliesToScan);

            return(services);
        }