예제 #1
0
        public DefaultBinderFactory(IApplicationContext context, IOptionsMonitor <BindingServiceOptions> optionsMonitor, IBinderConfigurations binderConfigurations, IEnumerable <IBinderFactoryListener> listeners = null)
        {
            if (binderConfigurations == null)
            {
                throw new ArgumentNullException(nameof(binderConfigurations));
            }

            _listeners            = listeners?.ToList();
            _context              = context;
            _optionsMonitor       = optionsMonitor;
            _binderConfigurations = binderConfigurations;
        }
예제 #2
0
        public DefaultBinderFactory(IServiceProvider services, IOptionsMonitor <BindingServiceOptions> optionsMonitor, IBinderConfigurations binderConfigurations, IEnumerable <IBinderFactoryListener> listeners = null)
        {
            if (binderConfigurations == null)
            {
                throw new ArgumentNullException(nameof(binderConfigurations));
            }

            _services             = services;
            _optionsMonitor       = optionsMonitor;
            _binderConfigurations = binderConfigurations;
            _listeners            = listeners?.ToList();
        }
예제 #3
0
        internal static void ConfigureBinderServices(this IServiceCollection services, IBinderConfigurations binderConfigurations, IConfiguration configuration)
        {
            foreach (var binderConfiguration in binderConfigurations.Configurations)
            {
                var type = FindConfigureType(binderConfiguration.Value);
                if (type != null)
                {
                    var constr = FindConstructor(type);
                    var method = FindConfigureServicesMethod(type);
                    if (constr != null && method != null)
                    {
                        try
                        {
                            var instance = constr.Invoke(new object[] { configuration });
                            if (instance != null)
                            {
                                method.Invoke(instance, new object[] { services });
                            }

                            binderConfiguration.Value.ResolvedAssembly = type.Assembly.Location;
                        }
                        catch (Exception)
                        {
                            // Log
                        }
                    }
                    else
                    {
                        // Log
                    }
                }
                else
                {
                    // Log
                }
            }
        }
예제 #4
0
 internal static void AddBinderServices(this IServiceCollection services, IBinderConfigurations binderConfigurations, IConfiguration configuration)
 {
     services.TryAddSingleton <IBinderFactory, DefaultBinderFactory>();
     services.ConfigureBinderServices(binderConfigurations, configuration);
 }