Ejemplo n.º 1
0
        public void TestDependencyInjection()
        {
            var config = new ConfigurationBuilder()
                         .SetBasePath(System.IO.Directory.GetCurrentDirectory())
                         .AddJsonFile($"appsettings.json", optional: true, reloadOnChange: false)
                         .AddEnvironmentVariables()
                         .Build();
            var services = new ServiceCollection();

            services.AddSingleton <IConfiguration>(config);


            var serviceProvider = IServiceCollectionExtension.AddInternalServices(services)
                                  .AddLogging()
                                  .BuildServiceProvider();


            var factory = serviceProvider.GetService <ILoggerFactory>();

            Assert.NotNull(factory);
            var authProvider = serviceProvider.GetService <IAuthenticationProvider>();

            Assert.NotNull(authProvider);
            var graphHelper = serviceProvider.GetService <IGraphUserHelper>();

            Assert.NotNull(graphHelper);
            //GraphClientLib.Class1 c = null;
        }
Ejemplo n.º 2
0
        public void Authenticate_With_Invalid_Credentials_Throws_AuthenticationException()
        {
            String    str = String.Format("Value cannot be null.{0}Parameter name: services", Environment.NewLine);
            Exception ex  = Assert.Throws <ArgumentNullException>(() => IServiceCollectionExtension.ScanInjections(null));

            Assert.Equal(str, ex.Message);
        }
Ejemplo n.º 3
0
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddRazorPages();
            services.AddServerSideBlazor();
            configLocalizationService(services);
            configBlazorizeService(services);

            IServiceCollectionExtension.AddInfraLibraryInjections(services, Configuration);
        }
Ejemplo n.º 4
0
        private ServiceProvider GetDIServiceProvider(IConfiguration config)
        {
            var services = new ServiceCollection();

            services.AddSingleton <IConfiguration>(config);


            var serviceProvider = IServiceCollectionExtension.AddInternalServices(services)
                                  .AddLogging()
                                  .BuildServiceProvider();

            return(serviceProvider);
        }
Ejemplo n.º 5
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.Configure <CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded    = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });

            services.AddDbContext <ApplicationDbContext>(options =>
                                                         options.UseSqlServer(
                                                             Configuration.GetConnectionString("DefaultConnection")));
            //services.AddDefaultIdentity<IdentityUser>()
            //    .AddDefaultUI(UIFramework.Bootstrap4)
            //    .AddEntityFrameworkStores<ApplicationDbContext>();
            services.AddIdentity <IdentityUser, IdentityRole>(options =>
            {
                options.User.RequireUniqueEmail         = false;
                options.Password.RequireLowercase       = false;
                options.Password.RequireNonAlphanumeric = false;
                options.Password.RequireUppercase       = false;
            })
            .AddDefaultUI(UIFramework.Bootstrap4)
            .AddEntityFrameworkStores <ApplicationDbContext>()
            .AddDefaultTokenProviders();

            var mappingConfig = new MapperConfiguration(mc =>
            {
                mc.AddProfile(new AutoMapperProfile());
            });

            IMapper mapper = mappingConfig.CreateMapper();

            services.AddSingleton(mapper);

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);

            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();

            IServiceCollectionExtension.RegisterServices(services);
        }