예제 #1
0
        public ProfileLocationSchema(ProfileLocationQuery query, ProfileLocationMutations mutation, ProfileLocationSubscriptions subscriptions, IServiceProvider serviceProvider)
        {
            Query        = query;
            Subscription = subscriptions;
            Services     = serviceProvider;

            if (mutation.Fields.Any())
            {
                Mutation = mutation;
            }
        }
        public static void AddProfileLocationConfig(this IServiceCollection services, IWebHostEnvironment environment, IConfiguration configuration)
        {
            services.AddTransient(s =>
            {
                var opt = new DbContextOptionsBuilder <ProfileLocationContextEF>();
                if (environment.EnvironmentName == "Testing")
                {
                    // Add In Memory Datatabase for unit test
                    opt.UseInMemoryDatabase("TestingProfileLocation");
                }
                else
                {
                    opt.UseSqlServer(configuration.GetConnectionString("ProfileLocationDatabase"));
                    opt.UseLazyLoadingProxies();
                }

                var ctx = new ProfileLocationContext(opt.Options);

                return(ctx);
            });

            // Add ProfileLocationUserContext
            services.AddScoped(ctx =>
            {
                var claimsPrincipal = ctx.GetService <ClaimsPrincipal>();
                return((IUserContext) new UserContextModel()
                {
                    Username = claimsPrincipal.FindFirst(ClaimTypes.NameIdentifier).Value,
                    DisplayName = claimsPrincipal.FindFirst("name").Value,
                    ApplicationID = Convert.ToInt32(claimsPrincipal.FindFirst("appid").Value),
                    UserID = Convert.ToInt32(claimsPrincipal.FindFirst("uid").Value),
                    Roles = claimsPrincipal.FindAll(ClaimTypes.Role)?.Select(s => s.Value).ToArray(),
                    Scopes = claimsPrincipal.FindAll("scope")?.Select(s => s.Value).ToArray(),
                });
            });

            //Entity Repositories
            #region Repositories

            services.AddTransient(typeof(IRepository <Group>), typeof(ProfileLocation.Data.EF.Repositories.GroupRepository));
            services.AddTransient(typeof(IRepository <Location>), typeof(ProfileLocation.Data.EF.Repositories.LocationRepository));
            services.AddTransient(typeof(IRepository <Profile>), typeof(ProfileLocation.Data.EF.Repositories.ProfileRepository));
            services.AddTransient(typeof(IRepository <ProfileGroup>), typeof(ProfileLocation.Data.EF.Repositories.ProfileGroupRepository));
            services.AddTransient(typeof(IRepository <Social>), typeof(ProfileLocation.Data.EF.Repositories.SocialRepository));
            services.AddTransient(typeof(IRepository <SocialType>), typeof(ProfileLocation.Data.EF.Repositories.SocialTypeRepository));
            #endregion

            //Register All Entity Types

            #region Group
            services.AddSingleton(typeof(ProfileLocation.WebAPI.Models.GraphQL.GroupType));
            services.AddSingleton(typeof(PagedListType <ProfileLocation.Domain.ORM.Models.Group, ProfileLocation.WebAPI.Models.GraphQL.GroupType>));
            services.AddSingleton(typeof(ProfileLocation.WebAPI.Models.GraphQL.Search.GroupSearchType));
            services.AddSingleton(typeof(ProfileLocation.WebAPI.Models.GraphQL.Input.GroupInputType));
            services.AddSingleton(typeof(ProfileLocation.WebAPI.Models.GraphQL.EntityFieldEnums.GroupEnumType));
            services.AddSingleton(typeof(SortOrderType <ProfileLocation.WebAPI.Models.GraphQL.EntityFieldEnums.GroupEnumType>));
            GraphTypeTypeRegistry.Register <ProfileLocation.Domain.ORM.Models.Group, ProfileLocation.WebAPI.Models.GraphQL.GroupType>();
            #endregion

            #region Location
            services.AddSingleton(typeof(ProfileLocation.WebAPI.Models.GraphQL.LocationType));
            services.AddSingleton(typeof(PagedListType <ProfileLocation.Domain.ORM.Models.Location, ProfileLocation.WebAPI.Models.GraphQL.LocationType>));
            services.AddSingleton(typeof(ProfileLocation.WebAPI.Models.GraphQL.Search.LocationSearchType));
            services.AddSingleton(typeof(ProfileLocation.WebAPI.Models.GraphQL.Input.LocationInputType));
            services.AddSingleton(typeof(ProfileLocation.WebAPI.Models.GraphQL.EntityFieldEnums.LocationEnumType));
            services.AddSingleton(typeof(SortOrderType <ProfileLocation.WebAPI.Models.GraphQL.EntityFieldEnums.LocationEnumType>));
            GraphTypeTypeRegistry.Register <ProfileLocation.Domain.ORM.Models.Location, ProfileLocation.WebAPI.Models.GraphQL.LocationType>();
            #endregion

            #region Profile
            services.AddSingleton(typeof(ProfileLocation.WebAPI.Models.GraphQL.ProfileType));
            services.AddSingleton(typeof(PagedListType <ProfileLocation.Domain.ORM.Models.Profile, ProfileLocation.WebAPI.Models.GraphQL.ProfileType>));
            services.AddSingleton(typeof(ProfileLocation.WebAPI.Models.GraphQL.Search.ProfileSearchType));
            services.AddSingleton(typeof(ProfileLocation.WebAPI.Models.GraphQL.Input.ProfileInputType));
            services.AddSingleton(typeof(ProfileLocation.WebAPI.Models.GraphQL.EntityFieldEnums.ProfileEnumType));
            services.AddSingleton(typeof(SortOrderType <ProfileLocation.WebAPI.Models.GraphQL.EntityFieldEnums.ProfileEnumType>));
            GraphTypeTypeRegistry.Register <ProfileLocation.Domain.ORM.Models.Profile, ProfileLocation.WebAPI.Models.GraphQL.ProfileType>();
            #endregion

            #region ProfileGroup
            services.AddSingleton(typeof(ProfileLocation.WebAPI.Models.GraphQL.ProfileGroupType));
            services.AddSingleton(typeof(PagedListType <ProfileLocation.Domain.ORM.Models.ProfileGroup, ProfileLocation.WebAPI.Models.GraphQL.ProfileGroupType>));
            services.AddSingleton(typeof(ProfileLocation.WebAPI.Models.GraphQL.Search.ProfileGroupSearchType));
            services.AddSingleton(typeof(ProfileLocation.WebAPI.Models.GraphQL.Input.ProfileGroupInputType));
            services.AddSingleton(typeof(ProfileLocation.WebAPI.Models.GraphQL.EntityFieldEnums.ProfileGroupEnumType));
            services.AddSingleton(typeof(SortOrderType <ProfileLocation.WebAPI.Models.GraphQL.EntityFieldEnums.ProfileGroupEnumType>));
            GraphTypeTypeRegistry.Register <ProfileLocation.Domain.ORM.Models.ProfileGroup, ProfileLocation.WebAPI.Models.GraphQL.ProfileGroupType>();
            #endregion

            #region Social
            services.AddSingleton(typeof(ProfileLocation.WebAPI.Models.GraphQL.SocialType));
            services.AddSingleton(typeof(PagedListType <ProfileLocation.Domain.ORM.Models.Social, ProfileLocation.WebAPI.Models.GraphQL.SocialType>));
            services.AddSingleton(typeof(ProfileLocation.WebAPI.Models.GraphQL.Search.SocialSearchType));
            services.AddSingleton(typeof(ProfileLocation.WebAPI.Models.GraphQL.Input.SocialInputType));
            services.AddSingleton(typeof(ProfileLocation.WebAPI.Models.GraphQL.EntityFieldEnums.SocialEnumType));
            services.AddSingleton(typeof(SortOrderType <ProfileLocation.WebAPI.Models.GraphQL.EntityFieldEnums.SocialEnumType>));
            GraphTypeTypeRegistry.Register <ProfileLocation.Domain.ORM.Models.Social, ProfileLocation.WebAPI.Models.GraphQL.SocialType>();
            #endregion

            #region SocialType
            services.AddSingleton(typeof(ProfileLocation.WebAPI.Models.GraphQL.SocialTypeType));
            services.AddSingleton(typeof(PagedListType <ProfileLocation.Domain.ORM.Models.SocialType, ProfileLocation.WebAPI.Models.GraphQL.SocialTypeType>));
            services.AddSingleton(typeof(ProfileLocation.WebAPI.Models.GraphQL.Search.SocialTypeSearchType));
            services.AddSingleton(typeof(ProfileLocation.WebAPI.Models.GraphQL.Input.SocialTypeInputType));
            services.AddSingleton(typeof(ProfileLocation.WebAPI.Models.GraphQL.EntityFieldEnums.SocialTypeEnumType));
            services.AddSingleton(typeof(SortOrderType <ProfileLocation.WebAPI.Models.GraphQL.EntityFieldEnums.SocialTypeEnumType>));
            GraphTypeTypeRegistry.Register <ProfileLocation.Domain.ORM.Models.SocialType, ProfileLocation.WebAPI.Models.GraphQL.SocialTypeType>();
            #endregion


            services.AddSingleton <ProfileLocationSubscriptions>();
            var mutations = new ProfileLocationMutations(environment);
            services.AddSingleton <ProfileLocationMutations>(mutations);

            var query = new ProfileLocationQuery();
            services.AddSingleton <ProfileLocationQuery>(query);


            var entityObjectEventService = new EntityObjectEventService();
            services.AddSingleton <IEntityObjectEventService>(ctx => entityObjectEventService);

            RegisterTriggers(entityObjectEventService);

            RegisterManagers(services, query, mutations);

            services.AddSingleton <ProfileLocationSchema>();
        }