当前位置: 首页>>代码示例>>C#>>正文


C# this.AddTransient方法代码示例

本文整理汇总了C#中this.AddTransient方法的典型用法代码示例。如果您正苦于以下问题:C# this.AddTransient方法的具体用法?C# this.AddTransient怎么用?C# this.AddTransient使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在this的用法示例。


在下文中一共展示了this.AddTransient方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddSmashLeagueData

        public static IServiceCollection AddSmashLeagueData(
            this IServiceCollection services,
            Action<SmashLeagueDataOptions> setup)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            if (setup == null)
            {
                throw new ArgumentNullException(nameof(setup));
            }

            var dataOptions = new SmashLeagueDataOptions();
            setup(dataOptions);

            services.AddEntityFramework()
                .AddSqlServer()
                .AddDbContext<SmashLeagueDbContext>(options =>
                {
                    options.UseSqlServer(dataOptions.ConnectionString);
                });

            services.AddIdentity<ApplicationUser, IdentityRole>()
                .AddEntityFrameworkStores<SmashLeagueDbContext>()
                .AddDefaultTokenProviders();

            services.AddTransient<ApplicationUserManager>();
            services.AddTransient<SmashLeagueDbInitializer>();

            return services;
        }
开发者ID:iteam-software,项目名称:smash-league,代码行数:33,代码来源:ServiceCollectionExtensions.cs

示例2: AddOrchardMvc

        public static IServiceCollection AddOrchardMvc(this IServiceCollection services)
        {
            services
                .AddMvcCore(options =>
                {
                    options.Filters.Add(new ModelBinderAccessorFilter());
                    options.Conventions.Add(new ModuleAreaRouteConstraintConvention());
                    options.ModelBinders.Insert(0, new CheckMarkModelBinder());
                })
                .AddViews()
                .AddViewLocalization()
                .AddRazorViewEngine()
                .AddJsonFormatters();

            services.AddScoped<IModelUpdaterAccessor, LocalModelBinderAccessor>();
            services.AddTransient<IFilterProvider, DependencyFilterProvider>();
            services.AddTransient<IMvcRazorHost, TagHelperMvcRazorHost>();

            services.AddScoped<IAssemblyProvider, OrchardMvcAssemblyProvider>();

            services.AddSingleton<ICompilationService, DefaultRoslynCompilationService>();

            services.Configure<RazorViewEngineOptions>(options =>
            {
                var expander = new ModuleViewLocationExpander();
                options.ViewLocationExpanders.Add(expander);
            });
            return services;
        }
开发者ID:MichaelPetrinolis,项目名称:Orchard2,代码行数:29,代码来源:ServiceCollectionExtensions.cs

示例3: AddStatementProcessing

 public static void AddStatementProcessing(this IServiceCollection services)
 {
     services.AddTransient<IBankAccountStatementProcessor, BankAccountStatementProcessor>();
     services.AddTransient<IBankAccountStatementParser, SberbankStatementParser>();
     services.AddTransient<IBankAccountStatementParser, TinkoffBankStatementParser>();
     services.AddTransient<AggregateStatementParser>();
 }
开发者ID:EvAlex,项目名称:BudgetAnalyzer,代码行数:7,代码来源:Extensions.cs

示例4: ConfigureApplicationDataAccess

 public static void ConfigureApplicationDataAccess(this IServiceCollection services, string redisConnectionString)
 {
     services.AddSingleton(serviceProvider =>
         ConnectionMultiplexer.Connect(redisConnectionString));
     services.AddTransient<IShortUrlRepository, ShortUrlRepository>();
     services.AddTransient<IUserRepository, UserRepository>();
 }
开发者ID:OlsonAndrewD,项目名称:the-phone-bible,代码行数:7,代码来源:StartupExtensions.cs

示例5: AddDapperApplicationBuilder

 public static IServiceCollection AddDapperApplicationBuilder(this IServiceCollection services)
 {
     services.AddTransient(provider =>
     {
         var conn = provider.GetService<SqlConnection>();
         var userStore = new UserStore(conn);
         var repo = new RepositoryOptions<User>
         {
             UserStore = userStore,
             UserEmailStore = new UserEmailStore(conn),
             UserLockoutStore = new UserLockoutStore(conn),
             UserLoginStore = new UserLoginStore(conn),
             UserPasswordStore = new UserPasswordStore(conn),
             UserPropertyStore = new UserPropertyStore(conn),
             UserRoleStore = new UserRoleStore(conn),
             UserTokenStore = new UserUpdateTokenStore(conn)
         };
         return new UserManager<User>(repo, provider.GetService<IEmailService>(),
             provider.GetService<ILogger<UserManager<User>>>(), TimeSpan.FromDays(1));
     });
     services.AddTransient(
         provider =>
         {
             var manager = provider.GetService<UserManager<User>>();
             return new LoginManager<User>(provider.GetService<UserManager<User>>(),
                 provider.GetService<ILogger<LoginManager<User>>>(),
                 new LoginManagerOptions<User>
                 {
                     ClaimsProvider = new ClaimsProvider<User>(manager, new ClaimTypesOptions())
                 });
         });
     return services;
 }
开发者ID:interopbyt,项目名称:InkySigma,代码行数:33,代码来源:AuthenticationExtentions.cs

示例6: AddOrchardMvc

        public static IServiceCollection AddOrchardMvc(this IServiceCollection services)
        {
            services
                .AddMvcCore(options =>
                {
                    options.Filters.Add(new ModelBinderAccessorFilter());
                    options.Filters.Add(typeof(AutoValidateAntiforgeryTokenAuthorizationFilter));
                    options.ModelBinderProviders.Insert(0, new CheckMarkModelBinderProvider());
                })
                .AddViews()
                .AddViewLocalization()
                .AddRazorViewEngine()
                .AddJsonFormatters();

            services.AddScoped<IModelUpdaterAccessor, LocalModelBinderAccessor>();
            services.AddTransient<IFilterProvider, DependencyFilterProvider>();
            services.AddTransient<IApplicationModelProvider, ModuleAreaRouteConstraintApplicationModelProvider>();

            services.Configure<RazorViewEngineOptions>(configureOptions: options =>
            {
                var expander = new ModuleViewLocationExpander();
                options.ViewLocationExpanders.Add(expander);

                var extensionLibraryService = services.BuildServiceProvider().GetService<IExtensionLibraryService>();
                ((List<MetadataReference>)options.AdditionalCompilationReferences).AddRange(extensionLibraryService.MetadataReferences());
            });

            return services;
        }
开发者ID:jchenga,项目名称:Orchard2,代码行数:29,代码来源:ServiceCollectionExtensions.cs

示例7: AddBrickPile

        public static void AddBrickPile(this IServiceCollection services)
        {
            _serviceProvider = services.BuildServiceProvider();

            services.AddMvc().ConfigureApplicationPartManager(manager =>
            {
                var feature = new ControllerFeature();
                manager.PopulateFeature(feature);
                services.AddSingleton<IControllerMapper>(new ControllerMapper(feature));
            });

            services.AddRouting(options =>
            {
                options.AppendTrailingSlash = true;
                options.LowercaseUrls = true;
            });

            services.Configure<MvcOptions>(options =>
            {
                options.ModelBinderProviders.Insert(0, new DefaultModelBinderProvider(DocumentStore));
                options.Filters.Add(typeof(PublishedFilterAttribute), 1);
                options.Filters.Add(typeof(AuthorizeFilterAttribute), 2);
            });

            services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
            services.AddSingleton(DocumentStore);
            services.AddTransient<IRouteResolverTrie>(provider => new RouteResolverTrie(provider.GetService<IDocumentStore>()));
            services.AddTransient<IBricsContextAccessor>(provider => new BricsContextAccessor(provider.GetService<IHttpContextAccessor>(), provider.GetService<IDocumentStore>()));
        }
开发者ID:marcuslindblom,项目名称:aspnet5,代码行数:29,代码来源:ServiceCollectionExtensions.cs

示例8: AddSmidge

        public static IServiceCollection AddSmidge(this IServiceCollection services)
        {
            //services.AddNodeServices(NodeHostingModel.Http);

            services.AddTransient<IConfigureOptions<SmidgeOptions>, SmidgeOptionsSetup>();
            services.AddTransient<IConfigureOptions<Bundles>, BundlesSetup>();
            services.AddSingleton<PreProcessPipelineFactory>();
            services.AddSingleton<BundleManager>();
            services.AddSingleton<FileSystemHelper>();
            services.AddSingleton<PreProcessManager>();
            services.AddSingleton<ISmidgeConfig, SmidgeConfig>();
            services.AddScoped<SmidgeContext>();
            services.AddScoped<SmidgeHelper>();
            services.AddSingleton<IUrlManager, DefaultUrlManager>();
            services.AddSingleton<IHasher, Crc32Hasher>();

            //pre-processors
            services.AddSingleton<IPreProcessor, JsMin>();
            services.AddSingleton<IPreProcessor, CssMinifier>();
            //services.AddSingleton<IPreProcessor, NodeMinifier>();
            services.AddScoped<IPreProcessor, CssImportProcessor>();
            services.AddScoped<IPreProcessor, CssUrlProcessor>();


            //Add the controller models as DI services - these get auto created for model binding
            services.AddTransient<BundleModel>();
            services.AddTransient<CompositeFileModel>();

            return services;
        }
开发者ID:eByte23,项目名称:Smidge,代码行数:30,代码来源:SmidgeStartup.cs

示例9: AddRsxBoxEmailWebApiAppService

 public static void AddRsxBoxEmailWebApiAppService(this IServiceCollection services)
 {
     services.AddTransient<IEmailManager<EmailTemplate, int>, InMemoryEmailManager>();
     services.AddTransient<IEmailTemplateManager<EmailTemplate, int>, InMemoryEmailTemplateManager<EmailTemplate>>();
     services.AddTransient<IEmailSender<EmailTemplate>, InMemoryEmailSender<EmailTemplate>>();
     services.AddTransient<SmtpClient>();
 }
开发者ID:RsxBox,项目名称:RsxBox.Email,代码行数:7,代码来源:EmailAppBuilderExtension.cs

示例10: AddUserCommandsRegistrations

 private static void AddUserCommandsRegistrations(this IServiceCollection serviceCollection)
 {
     serviceCollection.AddTransient<ICanExecuteRequest<CreateUserRequest, User>, CreateUserCommand>();
     serviceCollection.AddTransient<ICanExecuteRequest<GetUserRequest, User>, GetUserCommand>();
     serviceCollection.AddTransient<ICanExecuteRequest<CheckIfUserExistsRequest, bool>,CheckIfUserExistsCommand>();
     serviceCollection.AddTransient<ICanExecuteRequest<GetUserByIdRequest, User>, GetUserByIdCommand>();
 }
开发者ID:MightyDevelopers,项目名称:solutions,代码行数:7,代码来源:RepostitoryRegistrations.cs

示例11: AddRaygun

    public static IServiceCollection AddRaygun(this IServiceCollection services, IConfiguration configuration, RaygunMiddlewareSettings middlewareSettings)
    {
      services.Configure<RaygunSettings>(configuration.GetSection("RaygunSettings"));

      services.AddTransient(_ => middlewareSettings.ClientProvider ?? new DefaultRaygunAspNetCoreClientProvider());
      services.AddTransient(_ => middlewareSettings);

      return services;
    }
开发者ID:MindscapeHQ,项目名称:raygun4net,代码行数:9,代码来源:RaygunAspNetMiddleware.cs

示例12: AddHtmlLocalization

 public static IServiceCollection AddHtmlLocalization(this IServiceCollection services)
 {
     services.AddSingleton<IHtmlLocalizerFactory, HtmlLocalizerFactory>();
     services.AddTransient(typeof(IHtmlLocalizer<>), typeof(HtmlLocalizer<>));
     services.AddTransient(typeof(IViewLocalizer), typeof(ViewLocalizer));
     if (!services.Any(sd => sd.ServiceType == typeof(IHtmlEncoder)))
     {
         services.AddInstance<IHtmlEncoder>(HtmlEncoder.Default);
     }
     return services.AddLocalization();
 }
开发者ID:morarsebastian,项目名称:i18nStarterWeb,代码行数:11,代码来源:IServiceCollectionExtensions.cs

示例13: AddSwagger

        public static void AddSwagger(
            this IServiceCollection serviceCollection,
            Action<SwaggerOptions> configure = null)
        {
            serviceCollection.Configure<MvcOptions>(c =>
                c.Conventions.Add(new SwaggerApplicationConvention()));

            serviceCollection.Configure(configure ?? ((options) => {}));

            serviceCollection.AddTransient(GetSchemaRegistry);
            serviceCollection.AddTransient(GetSwaggerProvider);
        }
开发者ID:GoGoBlitz,项目名称:Ahoy,代码行数:12,代码来源:SwaggerServiceCollectionExtensions.cs

示例14: AddMvcWidgets

        /// <summary>
        /// Adds the MVC widgets services to the services collection.
        /// </summary>
        /// <param name="services">The collection of services.</param>
        /// <returns>The collection of services.</returns>
        public static IServiceCollection AddMvcWidgets(this IServiceCollection services)
        {
            services.AddSingleton<IWidgetSelector, DefaultWidgetSelector>();
            services.AddSingleton<IWidgetActivator, DefaultWidgetActivator>();
            services.AddSingleton<IWidgetDescriptorCollectionProvider, DefaultWidgetDescriptorCollectionProvider>();
            services.AddSingleton<IWidgetInvokerFactory, DefaultWidgetInvokerFactory>();
            services.AddSingleton<IWidgetArgumentBinder, DefaultWidgetArgumentBinder>();

            services.AddTransient<IWidgetDescriptorProvider, DefaultWidgetDescriptorProvider>();
            services.AddTransient<IWidgetHelper, DefaultWidgetHelper>();

            return services;
        }
开发者ID:Antaris,项目名称:AspNetCore.Mvc.Widgets,代码行数:18,代码来源:ServiceCollectionExtensions.cs

示例15: ConfigureApplicationServices

 public static void ConfigureApplicationServices(this IServiceCollection services, string digitalBiblePlatformApiKey, string googleMapsApiKey)
 {
     services.AddTransient<IBibleMetadataService, BibleMetadataService>();
     services.AddTransient<IContentService>(serviceProvider =>
         new DigitalBiblePlatformContentService(
             serviceProvider.GetRequiredService<IUserService>(),
             serviceProvider.GetRequiredService<IBibleMetadataService>(),
             digitalBiblePlatformApiKey));
     services.AddTransient<IShortUrlService, ShortUrlService>();
     services.AddTransient<ITimeService>(serviceProvider =>
         new TimeService(googleMapsApiKey));
     services.AddTransient<IUserService, UserService>();
 }
开发者ID:OlsonAndrewD,项目名称:the-phone-bible,代码行数:13,代码来源:StartupExtensions.cs


注:本文中的this.AddTransient方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。