protected virtual DbContextOptions <TDbContext> CreateOptions <TDbContext>([NotNull] string connectionString,
                                                                                   [CanBeNull] DbConnection existingConnection) where TDbContext : DbContext
        {
            if (iocResolver.IsRegistered <IStudioXDbContextConfigurer <TDbContext> >())
            {
                var configuration = new StudioXDbContextConfiguration <TDbContext>(connectionString, existingConnection);

                configuration.DbContextOptions
                .ReplaceService <IEntityMaterializerSource, StudioXEntityMaterializerSource>();

                using (var configurer = iocResolver.ResolveAsDisposable <IStudioXDbContextConfigurer <TDbContext> >())
                {
                    configurer.Object.Configure(configuration);
                }

                return(configuration.DbContextOptions.Options);
            }

            if (iocResolver.IsRegistered <DbContextOptions <TDbContext> >())
            {
                return(iocResolver.Resolve <DbContextOptions <TDbContext> >());
            }

            throw new StudioXException(
                      $"Could not resolve DbContextOptions for {typeof(TDbContext).AssemblyQualifiedName}.");
        }
        /// <summary>
        /// Called by MVC system and creates controller instance for given controller type.
        /// </summary>
        /// <param name="requestContext">Request context</param>
        /// <param name="controllerType">Controller type</param>
        /// <returns></returns>
        protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType)
        {
            if (controllerType == null || !_iocManager.IsRegistered(controllerType))
            {
                return(base.GetControllerInstance(requestContext, controllerType));
            }

            return(_iocManager.Resolve <IController>(controllerType));
        }
        /// <summary>
        /// This method is called by ABP before first usage.
        /// </summary>
        public virtual void Initialize(ILocalizationConfiguration configuration, IIocResolver iocResolver)
        {
            _configuration = configuration;

            _logger = iocResolver.IsRegistered(typeof(ILoggerFactory))
                ? iocResolver.Resolve <ILoggerFactory>().Create(typeof(ResourceFileLocalizationSource))
                : NullLogger.Instance;
        }
Beispiel #4
0
        public override void Initialize(ILocalizationConfiguration configuration, IIocResolver iocResolver)
        {
            base.Initialize(configuration, iocResolver);

            if (Logger is NullLogger && iocResolver.IsRegistered(typeof(ILoggerFactory)))
            {
                Logger = iocResolver.Resolve <ILoggerFactory>().Create(typeof(MultiTenantLocalizationSource));
            }
        }
Beispiel #5
0
        public override IValidator CreateInstance(Type validatorType)
        {
            if (_iocResolver.IsRegistered(validatorType))
            {
                return(_iocResolver.Resolve(validatorType) as IValidator);
            }

            return(null);
        }
        public override void Initialize(ILocalizationConfiguration configuration, IIocResolver iocResolver)
        {
            base.Initialize(configuration, iocResolver);

            if (Logger is NullLogger && iocResolver.IsRegistered(typeof(ILoggerFactory)))
            {
                Logger = iocResolver.Resolve<ILoggerFactory>().Create(typeof (MultiTenantLocalizationSource));
            }
        }
        private bool IsInitialized()
        {
            if (_isInitialized)
            {
                return(true);
            }

            _isInitialized = _iocResolver.IsRegistered <IEmbeddedResourceManager>() && _iocResolver.IsRegistered <IEmbeddedResourcesConfiguration>();
            return(_isInitialized);
        }
        /// <inheritdoc/>
        public virtual void Initialize(ILocalizationConfiguration configuration, IIocResolver iocResolver)
        {
            LocalizationConfiguration = configuration;

            _logger = iocResolver.IsRegistered(typeof(ILoggerFactory))
                ? iocResolver.Resolve <ILoggerFactory>().Create(typeof(DictionaryBasedLocalizationSource))
                : NullLogger.Instance;

            DictionaryProvider.Initialize(Name);
        }
        private bool IsInitialized()
        {
            if (_isInitialized)
            {
                return true;
            }

            _isInitialized = _iocResolver.IsRegistered<IEmbeddedResourceManager>();

            return _isInitialized;
        }
        protected virtual DbContextOptions <TDbContext> CreateOptions <TDbContext>(string connectionString, DbConnection existingConnection = null)
            where TDbContext : EfCoreDbContextBase
        {
            if (_iocResolver.IsRegistered <IDbContextOptionsResolver <TDbContext> >())
            {
                var dbContextOptionsResolver = _iocResolver.Resolve <IDbContextOptionsResolver <TDbContext> >();
                return(dbContextOptionsResolver.GetDbContextOptions(connectionString, existingConnection));
            }

            throw new DefaultException($"Couldn't resolve DbContextOptions for {typeof(TDbContext).AssemblyQualifiedName}.");
        }
        protected virtual DbContextOptions <TDbContext> CreateOptions <TDbContext>([NotNull] string connectionString, [CanBeNull] DbConnection existingConnection) where TDbContext : DbContext
        {
            if (_iocResolver.IsRegistered <IAbpDbContextConfigurer <TDbContext> >())
            {
                var configuration = new AbpDbContextConfiguration <TDbContext>(connectionString, existingConnection);

                using (var configurer = _iocResolver.ResolveAsDisposable <IAbpDbContextConfigurer <TDbContext> >())
                {
                    configurer.Object.Configure(configuration);
                }

                return(configuration.DbContextOptions.Options);
            }

            if (_iocResolver.IsRegistered <DbContextOptions <TDbContext> >())
            {
                return(_iocResolver.Resolve <DbContextOptions <TDbContext> >());
            }

            throw new AbpException($"Could not resolve DbContextOptions for {typeof(TDbContext).AssemblyQualifiedName}.");
        }
Beispiel #12
0
        private static string GetNameOrConnectionStringOrNull(IIocResolver iocResolver)
        {
            if (iocResolver.IsRegistered <IBdfStartupConfiguration>())
            {
                var defaultConnectionString = iocResolver.Resolve <IBdfStartupConfiguration>().DefaultNameOrConnectionString;
                if (!string.IsNullOrWhiteSpace(defaultConnectionString))
                {
                    return(defaultConnectionString);
                }
            }

            return(ConfigurationManager.ConnectionStrings["Default"] != null ? "Default" : null);
        }
        private static string GetNameOrConnectionStringOrNull(IIocResolver iocResolver)
        {
            if (iocResolver.IsRegistered<IBdfStartupConfiguration>())
            {
                var defaultConnectionString = iocResolver.Resolve<IBdfStartupConfiguration>().DefaultNameOrConnectionString;
                if (!string.IsNullOrWhiteSpace(defaultConnectionString))
                {
                    return defaultConnectionString;
                }
            }

            return ConfigurationManager.ConnectionStrings["Default"] != null ? "Default" : null;
        }
        protected override Type GetControllerType(RequestContext requestContext, string controllerName)
        {
            if (controllerName == null)
            {
                return(base.GetControllerType(requestContext, controllerName));
            }
            string area = requestContext.RouteData.GetAreaName();

            var serviceKey = ControllerConventionalRegistrar.GetControllerSerivceName(area, controllerName) + "Controller";

            object instance = default(object);

            if (!string.IsNullOrEmpty(area) && _iocManager.IsRegistered(serviceKey))
            {
                instance = _iocManager.Resolve <IController>(serviceKey);
            }
            return(instance != null?instance.GetType() : base.GetControllerType(requestContext, controllerName));
        }
        private void ConsumerOnReceived(object sender, BasicDeliverEventArgs e)
        {
            var json    = Encoding.UTF8.GetString(e.Body);
            var message = JsonConvert.DeserializeObject <MessageArgs>(json, new JsonSerializerSettings {
                TypeNameHandling = TypeNameHandling.All
            });

            var msgType = Type.GetType(message.AssemblyQualifiedName);

            ILogger logger = null;

            if (IocResolver.IsRegistered <ILogger>())
            {
                logger = IocResolver.Resolve <ILogger>();
            }

            using (var msgArgs = IocResolver.ResolveAsDisposable(msgType))
            {
                try
                {
                    var msgExecuteMethod = msgArgs.Object.GetType().GetMethod("Execute");
                    var argsType         = msgExecuteMethod.GetParameters()[0].ParameterType;
                    var args             = JsonConvert.DeserializeObject(message.Content, argsType);

                    msgExecuteMethod.Invoke(msgArgs.Object, new[] { args });

                    OnMessageReceived(new MessageReceivedEventArgs(message));
                    channel.BasicAck(e.DeliveryTag, multiple: false);
                }
                catch (Exception ex)
                {
                    if (logger != null)
                    {
                        logger.Warn(ex.Message, ex);
                    }
                }
            }
        }
        private static string GetNameOrConnectionStringOrNull(IIocResolver iocResolver)
        {
            if (iocResolver.IsRegistered<IAbpStartupConfiguration>())
            {
                var defaultConnectionString = iocResolver.Resolve<IAbpStartupConfiguration>().DefaultNameOrConnectionString;
                if (!string.IsNullOrWhiteSpace(defaultConnectionString))
                {
                    return defaultConnectionString;
                }
            }

            if (ConfigurationManager.ConnectionStrings.Count == 1)
            {
                return ConfigurationManager.ConnectionStrings[0].Name;
            }

            if (ConfigurationManager.ConnectionStrings["Default"] != null)
            {
                return "Default";
            }

            return null;
        }
Beispiel #17
0
 public bool IsRegistered(Type type)
 {
     return(_iocResolver.IsRegistered(type));
 }
Beispiel #18
0
        public void Build()
        {
            var types =
                from
                type in assembly.GetTypes()
                where
                (type.IsPublic || type.IsNestedPublic) &&
                type.IsInterface &&
                typeof(T).IsAssignableFrom(type) &&
                iocResolver.IsRegistered(type) &&
                !RemoteServiceAttribute.IsExplicitlyDisabledFor(type)
                select
                type;

            if (typePredicate != null)
            {
                types = types.Where(t => typePredicate(t));
            }

            foreach (var type in types)
            {
                var serviceName = serviceNameSelector != null
                    ? serviceNameSelector(type)
                    : GetConventionalServiceName(type);

                if (!string.IsNullOrWhiteSpace(servicePrefix))
                {
                    serviceName = servicePrefix + "/" + serviceName;
                }

                var builder = typeof(IDynamicApiControllerBuilder)
                              .GetMethod("For", BindingFlags.Public | BindingFlags.Instance)
                              .MakeGenericMethod(type)
                              .Invoke(dynamicApiControllerBuilder, new object[] { serviceName });

                if (filters != null)
                {
                    builder.GetType()
                    .GetMethod("WithFilters", BindingFlags.Public | BindingFlags.Instance)
                    .Invoke(builder, new object[] { filters });
                }

                if (isApiExplorerEnabled != null)
                {
                    builder.GetType()
                    .GetMethod("WithApiExplorer", BindingFlags.Public | BindingFlags.Instance)
                    .Invoke(builder, new object[] { isApiExplorerEnabled });
                }

                if (isProxyScriptingEnabled != null)
                {
                    builder.GetType()
                    .GetMethod("WithProxyScripts", BindingFlags.Public | BindingFlags.Instance)
                    .Invoke(builder, new object[] { isProxyScriptingEnabled.Value });
                }

                if (conventionalVerbs)
                {
                    builder.GetType()
                    .GetMethod("WithConventionalVerbs", BindingFlags.Public | BindingFlags.Instance)
                    .Invoke(builder, new object[0]);
                }

                if (forMethodsAction != null)
                {
                    builder.GetType()
                    .GetMethod("ForMethods", BindingFlags.Public | BindingFlags.Instance)
                    .Invoke(builder, new object[] { forMethodsAction });
                }

                builder.GetType()
                .GetMethod("Build", BindingFlags.Public | BindingFlags.Instance)
                .Invoke(builder, new object[0]);
            }
        }
Beispiel #19
0
 private static string GetConnectionString(IIocResolver iocResolver)
 {
     return(iocResolver.IsRegistered <IAbpStartupConfiguration>()
         ? iocResolver.Resolve <IAbpStartupConfiguration>().DefaultConnectionString
         : null);
 }