本文整理汇总了C#中SimpleInjector.Container.Bootstrap方法的典型用法代码示例。如果您正苦于以下问题:C# Container.Bootstrap方法的具体用法?C# Container.Bootstrap怎么用?C# Container.Bootstrap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SimpleInjector.Container
的用法示例。
在下文中一共展示了Container.Bootstrap方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Build
public static void Build(IAppBuilder app, Container container = null) {
var loggerFactory = Settings.Current.GetLoggerFactory();
var logger = loggerFactory.CreateLogger(nameof(AppBuilder));
if (container == null)
container = CreateContainer(loggerFactory, logger);
var config = new HttpConfiguration();
config.Formatters.Remove(config.Formatters.XmlFormatter);
config.Formatters.JsonFormatter.SerializerSettings.Formatting = Formatting.Indented;
SetupRouteConstraints(config);
container.RegisterWebApiControllers(config);
VerifyContainer(container);
config.DependencyResolver = new SimpleInjectorWebApiDependencyResolver(container);
var contractResolver = container.GetInstance<IContractResolver>();
var exceptionlessContractResolver = contractResolver as ExceptionlessContractResolver;
exceptionlessContractResolver?.UseDefaultResolverFor(typeof(Connection).Assembly);
config.Formatters.JsonFormatter.SerializerSettings.ContractResolver = contractResolver;
config.Services.Add(typeof(IExceptionLogger), new FoundatioExceptionLogger(loggerFactory.CreateLogger<FoundatioExceptionLogger>()));
config.Services.Replace(typeof(IExceptionHandler), container.GetInstance<ExceptionlessReferenceIdExceptionHandler>());
config.MessageHandlers.Add(container.GetInstance<XHttpMethodOverrideDelegatingHandler>());
config.MessageHandlers.Add(container.GetInstance<EncodingDelegatingHandler>());
config.MessageHandlers.Add(container.GetInstance<AuthMessageHandler>());
// Throttle api calls to X every 15 minutes by IP address.
config.MessageHandlers.Add(container.GetInstance<ThrottlingHandler>());
// Reject event posts in orgs over their max event limits.
config.MessageHandlers.Add(container.GetInstance<OverageHandler>());
EnableCors(config, app);
container.Bootstrap(config);
container.Bootstrap(app);
app.UseWebApi(config);
SetupSignalR(app, container, loggerFactory);
SetupSwagger(config);
if (Settings.Current.WebsiteMode == WebsiteMode.Dev)
Task.Run(async () => await CreateSampleDataAsync(container));
var context = new OwinContext(app.Properties);
var token = context.Get<CancellationToken>("host.OnAppDisposing");
RunMessageBusBroker(container, logger, token);
RunJobs(container, loggerFactory, logger, token);
logger.Info("Starting api...");
}
示例2: BuildWithContainer
public static void BuildWithContainer(IAppBuilder app, Container container) {
if (container == null)
throw new ArgumentNullException(nameof(container));
Config = new HttpConfiguration();
Config.Formatters.Remove(Config.Formatters.XmlFormatter);
Config.Formatters.JsonFormatter.SerializerSettings.Formatting = Formatting.Indented;
SetupRouteConstraints(Config);
container.RegisterWebApiControllers(Config);
VerifyContainer(container);
Config.DependencyResolver = new SimpleInjectorWebApiDependencyResolver(container);
var contractResolver = container.GetInstance<IContractResolver>();
var exceptionlessContractResolver = contractResolver as ExceptionlessContractResolver;
exceptionlessContractResolver?.UseDefaultResolverFor(typeof(Connection).Assembly);
Config.Formatters.JsonFormatter.SerializerSettings.ContractResolver = contractResolver;
Config.Services.Add(typeof(IExceptionLogger), new FoundatioExceptionLogger());
Config.Services.Replace(typeof(IExceptionHandler), container.GetInstance<ExceptionlessReferenceIdExceptionHandler>());
Config.MessageHandlers.Add(container.GetInstance<XHttpMethodOverrideDelegatingHandler>());
Config.MessageHandlers.Add(container.GetInstance<EncodingDelegatingHandler>());
Config.MessageHandlers.Add(container.GetInstance<AuthMessageHandler>());
// Throttle api calls to X every 15 minutes by IP address.
Config.MessageHandlers.Add(container.GetInstance<ThrottlingHandler>());
// Reject event posts in orgs over their max event limits.
Config.MessageHandlers.Add(container.GetInstance<OverageHandler>());
EnableCors(Config, app);
container.Bootstrap(Config);
container.Bootstrap(app);
Mapper.Configuration.ConstructServicesUsing(container.GetInstance);
app.UseWebApi(Config);
SetupSignalR(app, container);
SetupSwagger(Config);
if (Settings.Current.WebsiteMode == WebsiteMode.Dev)
Task.Run(async () => await CreateSampleDataAsync(container));
RunJobs(app);
Logger.Info().Message("Starting api...").Write();
}
示例3: BuildWithContainer
public static void BuildWithContainer(IAppBuilder app, Container container) {
if (container == null)
throw new ArgumentNullException(nameof(container));
Config = new HttpConfiguration();
Config.Formatters.Remove(Config.Formatters.XmlFormatter);
Config.Formatters.JsonFormatter.SerializerSettings.Formatting = Formatting.Indented;
SetupRouteConstraints(Config);
container.RegisterWebApiControllers(Config);
VerifyContainer(container);
Config.DependencyResolver = new SimpleInjectorWebApiDependencyResolver(container);
var contractResolver = container.GetInstance<IContractResolver>();
var exceptionlessContractResolver = contractResolver as ExceptionlessContractResolver;
exceptionlessContractResolver?.UseDefaultResolverFor(typeof(Connection).Assembly);
Config.Formatters.JsonFormatter.SerializerSettings.ContractResolver = contractResolver;
Config.Services.Add(typeof(IExceptionLogger), new NLogExceptionLogger());
Config.Services.Replace(typeof(IExceptionHandler), container.GetInstance<ExceptionlessReferenceIdExceptionHandler>());
Config.MessageHandlers.Add(container.GetInstance<XHttpMethodOverrideDelegatingHandler>());
Config.MessageHandlers.Add(container.GetInstance<EncodingDelegatingHandler>());
Config.MessageHandlers.Add(container.GetInstance<AuthMessageHandler>());
// Throttle api calls to X every 15 minutes by IP address.
Config.MessageHandlers.Add(container.GetInstance<ThrottlingHandler>());
// Reject event posts in orgs over their max event limits.
Config.MessageHandlers.Add(container.GetInstance<OverageHandler>());
EnableCors(Config, app);
container.Bootstrap(Config);
container.Bootstrap(app);
app.UseWebApi(Config);
var resolver = new SimpleInjectorSignalRDependencyResolver(container);
if (Settings.Current.EnableRedis)
resolver.UseRedis(new RedisScaleoutConfiguration(Settings.Current.RedisConnectionString, "exceptionless.signalr"));
app.MapSignalR("/api/v2/push", new HubConfiguration { Resolver = resolver });
SetupSwagger(Config);
Mapper.Configuration.ConstructServicesUsing(container.GetInstance);
if (Settings.Current.WebsiteMode == WebsiteMode.Dev)
Task.Run(async () => await CreateSampleDataAsync(container));
if (Settings.Current.RunJobsInProcess) {
Log.Warn().Message("Jobs running in process.").Write();
var context = new OwinContext(app.Properties);
var token = context.Get<CancellationToken>("host.OnAppDisposing");
JobRunner.RunContinuousAsync<EventPostsJob>(cancellationToken: token);
JobRunner.RunContinuousAsync<EventUserDescriptionsJob>(cancellationToken: token);
JobRunner.RunContinuousAsync<MailMessageJob>(cancellationToken: token);
JobRunner.RunContinuousAsync<EventNotificationsJob>(cancellationToken: token);
JobRunner.RunContinuousAsync<WebHooksJob>(cancellationToken: token);
JobRunner.RunContinuousAsync<DailySummaryJob>(cancellationToken: token, interval: TimeSpan.FromHours(1));
JobRunner.RunContinuousAsync<DownloadGeoIPDatabaseJob>(cancellationToken: token, interval: TimeSpan.FromDays(1));
JobRunner.RunContinuousAsync<RetentionLimitsJob>(cancellationToken: token, interval: TimeSpan.FromDays(1));
JobRunner.RunContinuousAsync<WorkItemJob>(instanceCount: 2, cancellationToken: token);
} else {
Log.Info().Message("Jobs running out of process.").Write();
}
Log.Info().Message("Starting api...").Write();
}
示例4: BuildWithContainer
public static void BuildWithContainer(IAppBuilder app, Container container) {
if (container == null)
throw new ArgumentNullException("container");
var contractResolver = container.GetInstance<IContractResolver>();
var exceptionlessContractResolver = contractResolver as ExceptionlessContractResolver;
if (exceptionlessContractResolver != null)
exceptionlessContractResolver.UseDefaultResolverFor(typeof(Connection).Assembly);
Config = new HttpConfiguration();
Config.DependencyResolver = new SimpleInjectorWebApiDependencyResolver(container);
Config.Formatters.Remove(Config.Formatters.XmlFormatter);
Config.Formatters.JsonFormatter.SerializerSettings.Formatting = Formatting.Indented;
Config.Formatters.JsonFormatter.SerializerSettings.ContractResolver = contractResolver;
SetupRouteConstraints(Config);
container.RegisterWebApiFilterProvider(Config);
VerifyContainer(container);
container.Bootstrap(Config);
container.Bootstrap(app);
Log.Info().Message("Starting api...").Write();
Config.Services.Add(typeof(IExceptionLogger), new NLogExceptionLogger());
Config.Services.Replace(typeof(IExceptionHandler), container.GetInstance<ExceptionlessReferenceIdExceptionHandler>());
Config.MessageHandlers.Add(container.GetInstance<XHttpMethodOverrideDelegatingHandler>());
Config.MessageHandlers.Add(container.GetInstance<EncodingDelegatingHandler>());
Config.MessageHandlers.Add(container.GetInstance<AuthMessageHandler>());
// Throttle api calls to X every 15 minutes by IP address.
Config.MessageHandlers.Add(container.GetInstance<ThrottlingHandler>());
// Reject event posts in orgs over their max event limits.
Config.MessageHandlers.Add(container.GetInstance<OverageHandler>());
app.UseCors(new CorsOptions {
PolicyProvider = new CorsPolicyProvider {
PolicyResolver = ctx => Task.FromResult(new CorsPolicy {
AllowAnyHeader = true,
AllowAnyMethod = true,
AllowAnyOrigin = true,
SupportsCredentials = true,
PreflightMaxAge = 60 * 5
})
}
});
app.CreatePerContext<Lazy<User>>("User", ctx => new Lazy<User>(() => {
if (ctx.Request.User == null || ctx.Request.User.Identity == null || !ctx.Request.User.Identity.IsAuthenticated)
return null;
string userId = ctx.Request.User.GetUserId();
if (String.IsNullOrEmpty(userId))
return null;
var userRepository = container.GetInstance<IUserRepository>();
return userRepository.GetById(userId, true);
}));
app.CreatePerContext<Lazy<Project>>("DefaultProject", ctx => new Lazy<Project>(() => {
if (ctx.Request.User == null || ctx.Request.User.Identity == null || !ctx.Request.User.Identity.IsAuthenticated)
return null;
// TODO: Use project id from url. E.G., /projects/{projectId:objectid}/events
string projectId = ctx.Request.User.GetDefaultProjectId();
var projectRepository = container.GetInstance<IProjectRepository>();
if (String.IsNullOrEmpty(projectId)) {
var firstOrgId = ctx.Request.User.GetOrganizationIds().FirstOrDefault();
if (!String.IsNullOrEmpty(firstOrgId)) {
var project = projectRepository.GetByOrganizationId(firstOrgId, useCache: true).Documents.FirstOrDefault();
if (project != null)
return project;
}
if (Settings.Current.WebsiteMode == WebsiteMode.Dev) {
var dataHelper = container.GetInstance<DataHelper>();
// create a default org and project
projectId = dataHelper.CreateDefaultOrganizationAndProject(ctx.Request.GetUser());
}
}
if (String.IsNullOrEmpty(projectId))
return null;
return projectRepository.GetById(projectId, true);
}));
app.UseWebApi(Config);
var resolver = new SimpleInjectorSignalRDependencyResolver(container);
if (Settings.Current.EnableRedis)
resolver.UseRedis(new RedisScaleoutConfiguration(Settings.Current.RedisConnectionString, "exceptionless.signalr"));
app.MapSignalR("/api/v2/push", new HubConfiguration { Resolver = resolver });
SetupSwagger(Config);
Mapper.Configuration.ConstructServicesUsing(container.GetInstance);
CreateSampleData(container);
//.........这里部分代码省略.........