Esempio n. 1
0
        public void Register(IAppHost appHost)
        {
            foreach (var entry in ImplicitConventions)
            {
                var key = entry.Key.Trim('%');
                var fmt = entry.Value;
                var query = new QueryDbFieldAttribute {
                    Template = fmt
                }.Init();
                if (entry.Key.EndsWith("%"))
                {
                    StartsWithConventions[key] = query;
                }
                if (entry.Key.StartsWith("%"))
                {
                    EndsWithConventions[key] = query;
                }
            }

            appHost.GetContainer().Register <IAutoQuery>(c =>
                                                         new AutoQuery
            {
                IgnoreProperties         = IgnoreProperties,
                IllegalSqlFragmentTokens = IllegalSqlFragmentTokens,
                MaxLimit                      = MaxLimit,
                EnableUntypedQueries          = EnableUntypedQueries,
                EnableSqlFilters              = EnableRawSqlFilters,
                OrderByPrimaryKeyOnLimitQuery = OrderByPrimaryKeyOnPagedQuery,
                QueryFilters                  = QueryFilters,
                ResponseFilters               = ResponseFilters,
                StartsWithConventions         = StartsWithConventions,
                EndsWithConventions           = EndsWithConventions,
                UseNamedConnection            = UseNamedConnection,
            })
            .ReusedWithin(ReuseScope.None);

            appHost.Metadata.GetOperationAssemblies()
            .Each(x => LoadFromAssemblies.Add(x));

            ((ServiceStackHost)appHost).ServiceAssemblies.Each(x => {
                if (!LoadFromAssemblies.Contains(x))
                {
                    LoadFromAssemblies.Add(x);
                }
            });

            if (EnableAutoQueryViewer && appHost.GetPlugin <AutoQueryMetadataFeature>() == null)
            {
                appHost.LoadPlugin(new AutoQueryMetadataFeature {
                    MaxLimit = MaxLimit
                });
            }
        }
Esempio n. 2
0
        public void AfterPluginsLoaded(IAppHost appHost)
        {
            var scannedTypes = LoadFromAssemblies.SelectMany(x => x.GetTypes());

            var misingRequestTypes = scannedTypes
                .Where(x => x.HasInterface(typeof(IQuery)))
                .Where(x => !appHost.Metadata.OperationsMap.ContainsKey(x))
                .ToList();

            if (misingRequestTypes.Count == 0)
                return;

            var serviceType = GenerateMissingServices(misingRequestTypes);
            appHost.RegisterService(serviceType);
        }
Esempio n. 3
0
        public void Register(IAppHost appHost)
        {
            foreach (var entry in ImplicitConventions)
            {
                var key = entry.Key.Trim('%');
                var fmt = entry.Value;
                var query = new QueryFieldAttribute {
                    Template = fmt
                }.Init();
                if (entry.Key.EndsWith("%"))
                {
                    StartsWithConventions[key] = query;
                }
                if (entry.Key.StartsWith("%"))
                {
                    EndsWithConventions[key] = query;
                }
            }

            appHost.GetContainer().Register <IAutoQuery>(c =>
                                                         new AutoQuery
            {
                IgnoreProperties         = IgnoreProperties,
                IllegalSqlFragmentTokens = IllegalSqlFragmentTokens,
                MaxLimit                      = MaxLimit,
                EnableUntypedQueries          = EnableUntypedQueries,
                EnableSqlFilters              = EnableRawSqlFilters,
                OrderByPrimaryKeyOnLimitQuery = OrderByPrimaryKeyOnPagedQuery,
                QueryFilters                  = QueryFilters,
                ResponseFilters               = ResponseFilters,
                StartsWithConventions         = StartsWithConventions,
                EndsWithConventions           = EndsWithConventions,
                Db = UseNamedConnection != null
                        ? c.Resolve <IDbConnectionFactory>().OpenDbConnection(UseNamedConnection)
                        : c.Resolve <IDbConnectionFactory>().OpenDbConnection(),
            })
            .ReusedWithin(ReuseScope.None);

            appHost.Metadata.GetOperationAssemblies()
            .Each(x => LoadFromAssemblies.Add(x));

            if (EnableAutoQueryViewer)
            {
                appHost.RegisterService <AutoQueryMetadataService>();
            }
        }
        public void Register(IAppHost appHost)
        {
            if (StripUpperInLike)
            {
                if (ImplicitConventions.TryGetValue("%Like%", out var convention) && convention == CaseInsensitiveLikeFormat)
                {
                    ImplicitConventions["%Like%"] = CaseSensitiveLikeFormat;
                }

                foreach (var attr in EndsWithConventions)
                {
                    if (attr.Value.Template == CaseInsensitiveLikeFormat)
                    {
                        attr.Value.Template = CaseSensitiveLikeFormat;
                    }
                }
            }

            foreach (var entry in ImplicitConventions)
            {
                var key = entry.Key.Trim('%');
                var fmt = entry.Value;
                var query = new QueryDbFieldAttribute {
                    Template = fmt
                }.Init();
                if (entry.Key.EndsWith("%"))
                {
                    StartsWithConventions[key] = query;
                }
                if (entry.Key.StartsWith("%"))
                {
                    EndsWithConventions[key] = query;
                }
            }

            appHost.GetContainer().Register <IAutoQueryDb>(c => new AutoQuery
            {
                IgnoreProperties         = IgnoreProperties,
                IllegalSqlFragmentTokens = IllegalSqlFragmentTokens,
                MaxLimit                      = MaxLimit,
                IncludeTotal                  = IncludeTotal,
                EnableUntypedQueries          = EnableUntypedQueries,
                EnableSqlFilters              = EnableRawSqlFilters,
                OrderByPrimaryKeyOnLimitQuery = OrderByPrimaryKeyOnPagedQuery,
                QueryFilters                  = QueryFilters,
                ResponseFilters               = ResponseFilters,
                StartsWithConventions         = StartsWithConventions,
                EndsWithConventions           = EndsWithConventions,
                UseNamedConnection            = UseNamedConnection,
            })
            .ReusedWithin(ReuseScope.None);

            appHost.Metadata.GetOperationAssemblies()
            .Each(x => LoadFromAssemblies.Add(x));

            appHost.ServiceAssemblies.Each(x => {
                if (!LoadFromAssemblies.Contains(x))
                {
                    LoadFromAssemblies.Add(x);
                }
            });

            if (EnableAutoQueryViewer && appHost.GetPlugin <AutoQueryMetadataFeature>() == null)
            {
                appHost.LoadPlugin(new AutoQueryMetadataFeature {
                    MaxLimit = MaxLimit
                });
            }

            appHost.GetPlugin <MetadataFeature>()
            ?.AddLink(MetadataFeature.AvailableFeatures, "http://docs.servicestack.net/autoquery", nameof(AutoQueryFeature));
        }