Beispiel #1
0
        public void FuncDependencyResolver_UnregisterCurrent()
        {
            bool   unregisterAllCalled = false;
            Type   type     = null;
            string contract = null;

            var currentMutable = new FuncDependencyResolver(
                (funcType, funcContract) => Array.Empty <object>(),
                unregisterCurrent: (passedType, passedContract) =>
            {
                unregisterAllCalled = true;
                contract            = passedContract;
                type = passedType;
            });

            currentMutable.UnregisterCurrent <IDummyInterface>();
            type.ShouldBe(typeof(IDummyInterface));
            contract.ShouldBeNull();
            unregisterAllCalled.ShouldBeTrue();

            unregisterAllCalled = false;
            currentMutable.UnregisterCurrent <IEnableLogger>("test");
            type.ShouldBe(typeof(IEnableLogger));
            contract.ShouldBe("test");
            unregisterAllCalled.ShouldBeTrue();
        }
        public AppBootstrapper(IKernel testKernel = null)
        {
            var kernel = testKernel ?? new StandardKernel();
            
             //Set up NInject to do DI
            var customResolver = new FuncDependencyResolver(
                (service, contract) =>
                {
                    if (contract != null) return kernel.GetAll(service, contract);
                    var items = kernel.GetAll(service);
                    var list = items.ToList();
                    return list;
                },
                (factory, service, contract) =>
                {
                    var binding = kernel.Bind(service).ToMethod(_ => factory());
                    if (contract != null) binding.Named(contract);
                });

            Locator.Current = customResolver;
            //Locator.Current = new NInjectDependencyResolver(kernel);

            LogHost.Default.Level = LogLevel.Debug;

            kernel.Bind<IScreen>().ToMethod(_ => new XamFormsAppScreen()).InSingletonScope();

            RegisterViews(kernel);
            RegisterViewModels(kernel);
            RegisterServices(kernel);

            DebugState.Set();
        }
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();

            services.AddSingleton <IDocumentExecuter, DocumentExecuter>();
            services.AddSingleton <GqlSampleMutation>();
            services.AddSingleton <GqlSampleQuery>();
            services.AddSingleton <ItemType>();

            var sp          = services.BuildServiceProvider();
            var gqlResolver = new FuncDependencyResolver(type => sp.GetService(type));
            var gqlSchema   = new GqlSampleSchema(gqlResolver);

            services.AddSingleton <GraphQL.Types.ISchema>(gqlSchema);
        }
        public AppBootstrapper(IKernel testKernel = null, RoutingState testRouter = null)
        {
            var kernel = testKernel ?? new StandardKernel();
            
             //Set up NInject to do DI
            var customResolver = new FuncDependencyResolver(
                (service, contract) =>
                {
                    if (contract != null) return kernel.GetAll(service, contract);
                    var items = kernel.GetAll(service);
                    var list = items.ToList();
                    return list;
                },
                (factory, service, contract) =>
                {
                    var binding = kernel.Bind(service).ToMethod(_ => factory());
                    if (contract != null) binding.Named(contract);
                });

            Locator.Current = customResolver;
            //Locator.Current = new NInjectDependencyResolver(kernel);

            LogHost.Default.Level = LogLevel.Debug;


            //initing Router at the end to postpone call to RxApp static ctor
            this.Router = testRouter ?? new RoutingState();

            kernel.Bind<IScreen>().ToConstant(this);

            this.RegisterViews(kernel);
            this.RegisterViewModels(kernel);
            this.RegisterServices(kernel);

            DebugState.Set();
        }
Beispiel #5
0
        protected override void Load(ContainerBuilder builder)
        {
            builder.RegisterType <HttpContextAccessor>().AsImplementedInterfaces();
            builder.Register(c => new DocumentWriter(false)).AsImplementedInterfaces().SingleInstance();
            builder.RegisterType <DocumentExecuter>().AsImplementedInterfaces().SingleInstance();
            builder.RegisterType <ContextServiceLocator>().SingleInstance();
            builder.RegisterType <EmployeePlatformSchema>().As <ISchema>().SingleInstance();
            builder.RegisterType <DocumentExecuter>().As <IDocumentExecuter>().SingleInstance();
            builder.RegisterType <EmployeePlatformQuery>().SingleInstance();
            builder.RegisterType <EmployeePlatformMutation>().SingleInstance();
            builder.RegisterType <AreaType>().SingleInstance();
            builder.RegisterType <SubareaType>().SingleInstance();
            builder.RegisterType <IdentificationTypesType>().SingleInstance();
            builder.RegisterType <EmployeePaginateType>().SingleInstance();
            builder.RegisterType <EmployeeType>().SingleInstance();
            builder.RegisterType <EmployeeTypeInput>();
            builder.RegisterType <EmployeeTypeUpdateInput>();
            builder.RegisterType <UserType>();
            builder.RegisterType <UserResponseAuthenticateType>();
            builder.RegisterType <SignupTypeInput>();
            builder.RegisterType <LoginTypeInput>();
            builder.Register(c =>
            {
                var cc = c.Resolve <IComponentContext>();
                var dependencyResolver = new FuncDependencyResolver(type => cc.Resolve(type));
                return(new EmployeePlatformSchema(dependencyResolver));
            }).AsSelf().AsImplementedInterfaces().SingleInstance();


            builder.RegisterType <AreaRepository>().As <IAreaRepository>();
            builder.RegisterType <SubareaRepository>().As <ISubareaRepository>();
            builder.RegisterType <IdentificationTypeRepository>().As <IIdentificationTypeRepository>();
            builder.RegisterType <EmployeeRepository>().As <IEmployeeRepository>();
            builder.RegisterType <UserRepository>().As <IUserRepository>();
            builder.RegisterType <PaginationRepository>().As <IPaginationRepository>();
        }
Beispiel #6
0
 public AppSchema(RootQueryGraphType query, FuncDependencyResolver resolver, RootMutationGraphType mutation)
 {
     this.Query              = query;
     this.Mutation           = mutation;
     this.DependencyResolver = resolver;
 }
Beispiel #7
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // Add framework services.
            services.AddMvc();

            var connection = Configuration.GetConnectionString("DepanneurDb");

            services.AddDbContext <DepanneurContext>(options => options.UseSqlServer(connection));

            services.AddIdentity <User, IdentityRole>()
            .AddEntityFrameworkStores <DepanneurContext>()
            .AddDefaultTokenProviders();

            services.AddAuthentication()
            .AddGoogle(options => {
                var googleAuthConfig = Configuration.GetSection("GoogleAuth");

                options.ClientId     = googleAuthConfig["ClientId"];
                options.ClientSecret = googleAuthConfig["ClientSecret"];

                // https://github.com/aspnet/AspNetCore/issues/6069#issuecomment-449461197
                options.UserInformationEndpoint = "https://www.googleapis.com/oauth2/v2/userinfo";
                options.ClaimActions.Clear();
                options.ClaimActions.MapJsonKey(ClaimTypes.NameIdentifier, "id");
                options.ClaimActions.MapJsonKey(ClaimTypes.Name, "name");
                options.ClaimActions.MapJsonKey(ClaimTypes.GivenName, "given_name");
                options.ClaimActions.MapJsonKey(ClaimTypes.Surname, "family_name");
                options.ClaimActions.MapJsonKey("urn:google:profile", "link");
                options.ClaimActions.MapJsonKey(ClaimTypes.Email, "email");
                options.ClaimActions.MapJsonKey("urn:google:image", "picture");
            });

            /* TODO PERFO: Faudrait mettre un interval raisonnable ici, ex: 1 minute.
             * Sauf qu'il y a un problèmee que je ne comprend pas.
             *
             * Supposons qu'un user se log, et qu'il a le rôle PRODUCTS.
             * Si on lui retire le rôle pendant qu'il est loggé, je m'attendrais à ce que
             * son cookie soit updaté après le délais indiqué.
             *
             * Toutefois, ce qui ce produit, c'est qu'à la première requête après le délais,
             * ses rôles sont bel et bien à jour (et ya même un Set-Cookie envoyé), sauf que
             * pour les autres requêtes d'après il revient à ses rôles d'avant.
             *
             * Je ne comprend pas pourquoi ce problème survient. Pour le moment, je configure
             * une interval négative afin de forcer un refresh à toutes les requêtes. Ça a
             * l'avantage que les rôles sont toujours à jour, mais l'inconvénient que ça
             * génère des requêtes BD pour chaque requête HTTP.
             */
            services.Configure <SecurityStampValidatorOptions>(x => {
                x.ValidationInterval = TimeSpan.FromSeconds(-1);
            });

            services.AddHangfire(x => x.UseSqlServerStorage(connection));
            services.AddScoped <SendWeekRecapJob>();
            services.AddScoped <ProcessSubscriptionsJob>();

            services.AddScoped <ProductRepository>();
            services.AddScoped <UserRepository>();
            services.AddScoped <SubscriptionRepository>();
            services.AddScoped <TransactionRepository>();

            services.AddScoped <TransactionService>();
            services.AddScoped <UserService>();

            services.AddSingleton <IDocumentExecuter, DocumentExecuter>();
            services.AddSingleton <IDataLoaderContextAccessor, DataLoaderContextAccessor>();
            services.AddSingleton <DataLoaderDocumentListener>();
            services.AddSingleton <DataLoader>();
            services.AddScoped <ISchema>(sp => {
                var resolver = new FuncDependencyResolver(type => sp.GetService(type) ?? ActivatorUtilities.CreateInstance(sp, type));
                return(new DepanneurSchema(resolver));
            });

            services.AddSingleton <IAuthorizationEvaluator, AuthorizationEvaluator>();
            services.AddScoped <IValidationRule, AuthorizationValidationRule>();
            services.AddSingleton(s => {
                var authSettings = new AuthorizationSettings();

                authSettings.AddPolicy(Policies.ManageUsers, x => x.RequireClaim(ClaimTypes.Role, Roles.Users));
                authSettings.AddPolicy(Policies.Balances, x => x.RequireClaim(ClaimTypes.Role, Roles.Balances));
                authSettings.AddPolicy(Policies.ManageProducts, x => x.RequireClaim(ClaimTypes.Role, Roles.Products));

                authSettings.AddPolicy(Policies.ReadUsers, policy => {
                    // Allowed if current user has any role
                    policy.RequireClaim(ClaimTypes.Role);
                });

                return(authSettings);
            });
        }
Beispiel #8
0
        /// <summary>
        /// This method will initialize your custom service locator with the 
        /// built-in RxUI types. Use this to help initialize containers that
        /// don't conform easily to IMutableDependencyResolver.
        /// </summary>
        /// <param name="registerMethod">Create a method here that will 
        /// register a constant. For example, the NInject version of
        /// this method might look like:
        /// 
        /// (obj, type) => kernel.Bind(type).ToConstant(obj)
        /// </param>
        public static void InitializeCustomResolver(Action<object, Type> registerMethod)
        {
            var fakeResolver = new FuncDependencyResolver(null,
                (fac, type, str) => registerMethod(fac(), type));

            fakeResolver.InitializeResolver();
        }
Beispiel #9
0
 /// <inheritdoc />
 public ZevereSchema(FuncDependencyResolver resolver)
 {
     DependencyResolver = resolver;
     Query    = resolver.Resolve <ZevereQuery>();
     Mutation = resolver.Resolve <ZevereMutation>();
 }
 public CurriculumVitaeSchema(FuncDependencyResolver resolver)
     : base(resolver)
 {
     Query = resolver.Resolve <CurriculumVitaeQuery>();
 }