本文整理汇总了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;
}
示例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;
}
示例3: AddStatementProcessing
public static void AddStatementProcessing(this IServiceCollection services)
{
services.AddTransient<IBankAccountStatementProcessor, BankAccountStatementProcessor>();
services.AddTransient<IBankAccountStatementParser, SberbankStatementParser>();
services.AddTransient<IBankAccountStatementParser, TinkoffBankStatementParser>();
services.AddTransient<AggregateStatementParser>();
}
示例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>();
}
示例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;
}
示例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;
}
示例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>()));
}
示例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;
}
示例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>();
}
示例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>();
}
示例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;
}
示例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();
}
示例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);
}
示例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;
}
示例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>();
}