public void ConfigureContainer(ContainerBuilder builder) { IoCBootstrapper.ConfigureContainer(builder); builder.RegisterType <SchedulerUrlGenerationService>() .As <ISchedulerUrlGenerationService>() .InstancePerLifetimeScope(); }
public static void Initialize() { var container = new Container(); container.Options.DefaultScopedLifestyle = new AsyncScopedLifestyle(); IoCBootstrapper.InitializeContainer(container); container.RegisterWebApiControllers(GlobalConfiguration.Configuration); container.Verify(); GlobalConfiguration.Configuration.DependencyResolver = new SimpleInjectorWebApiDependencyResolver(container); }
public static void Initialize() { var container = new Container(); container.Options.DefaultScopedLifestyle = new WebRequestLifestyle(); IoCBootstrapper.InitializeContainer(container); container.RegisterMvcControllers(Assembly.GetExecutingAssembly()); container.Verify(); DependencyResolver.SetResolver(new SimpleInjectorDependencyResolver(container)); }
public void Arrange(double expectedTotalAmount) { var container = IoCBootstrapper.Init(); CheckOutProcessor = container.Resolve <CheckOutProcessor>(); var productRepository = container.Resolve <IProductRepository>(); _products = productRepository.GetProducts(); ExpectedTotalAmount = expectedTotalAmount; }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddMediatR(typeof(Startup)); services.AddControllers(); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "ProcessManager", Version = "v1" }); }); LoggerBootstrapper.Initialize(); IoCBootstrapper.Initialize(services); }
private static void Main(string[] args) { var container = IoCBootstrapper.Init(); using (var scope = container.BeginLifetimeScope()) { var service = scope.Resolve <SampleService>(); service.Start(); Console.WriteLine("Service started, press enter to quit..."); Console.ReadLine(); service.Stop(); } }
protected void Application_Start() { // Set the dependency resolver for MVC. var mvcContainer = IoCBootstrapper.GetMvcContainer(); DependencyResolver.SetResolver(new SimpleInjectorDependencyResolver(mvcContainer)); // Set the dependency resolver for Web API. var apiContainer = IoCBootstrapper.GetApiContainer(); GlobalConfiguration.Configuration.DependencyResolver = new SimpleInjectorWebApiDependencyResolver(apiContainer); AreaRegistration.RegisterAllAreas(); GlobalConfiguration.Configure(WebApiConfig.Register); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); }
private static void Main() { var container = IoCBootstrapper.Init(); HostFactory.Run( h => { h.SetServiceName("Jobbie.Sample.Client.WebApi.Host"); h.SetDisplayName("Jobbie.Sample.Client.WebApi.Host"); h.UseAutofacContainer(container); h.Service <HostService>( s => { s.ConstructUsingAutofacContainer(); s.WhenStarted(x => x.Start()); s.WhenStopped(x => x.Stop()); }); }); }
private static void Main() { ConfigureLogging(); HostFactory.Run( h => { h.SetServiceName("Jobbie.Sample.Executor.Host"); h.SetDisplayName("Jobbie.Sample.Executor.Host"); h.UseAutofacContainer(IoCBootstrapper.Init()); h.Service <HostService>( s => { s.ConstructUsingAutofacContainer(); s.WhenStarted(x => x.Start()); s.WhenStopped(x => x.Stop()); }); }); }
public IServiceProvider ConfigureServices(IServiceCollection services) { services.AddLocalization(options => options.ResourcesPath = "Resources"); ///mvc 加过滤器 services.AddMvc(cfg => { cfg.Filters.Add(typeof(HandleException)); }).AddViewLocalization().AddDataAnnotationsLocalization(); services.AddOptions(); services.AddMemoryCache(); services.AddSession(options => { // Set a short timeout for easy testing. options.IdleTimeout = TimeSpan.FromMinutes(60); }); services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme) .AddCookie(options => { options.LoginPath = "/Login/Index"; options.LogoutPath = "/Login/Logout"; options.AccessDeniedPath = "/Login/NoRight"; }); services.Configure <FormOptions>(options => { options.MultipartBodyLengthLimit = 1024 * 1024 * 2; }); services.Configure <ConnectionStrings>(Configuration.GetSection("ConnectionStrings")); services.Configure <TestCore.MvcUtils.Admin.AppSettings>(Configuration.GetSection("AppSettings")); services.Configure <ApiSettings>(Configuration.GetSection("ApiSettings")); ///httpContext 使用 services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); var ServiceProvider = IoCBootstrapper.Startup(services); return(ServiceProvider); }
public LoadedXMLProvisioningTemplate LoadXmlTemplate(string containerName = "") { LoadedXMLProvisioningTemplate loadedTemplate = new LoadedXMLProvisioningTemplate() { ResourcesPath = this.ResourcesPath, TemplateFileName = this.TemplateFileName, TemplateFolderPath = this.TemplateFolderPath, }; try { loadedTemplate.Provider = new OfficeDevPnP.Core.Framework.Provisioning.Providers.Xml.XMLFileSystemTemplateProvider(this.TemplateFolderPath, containerName); loadedTemplate.Template = loadedTemplate.Provider.GetTemplate(this.TemplateFileName); loadedTemplate.Template.Connector = new OfficeDevPnP.Core.Framework.Provisioning.Connectors.FileSystemConnector(this.ResourcesPath, containerName); } catch (Exception ex) { var logService = IoCBootstrapper.GetLoggerInstance(); logService.Info(string.Format("Error parsing Provisioning Template: {0}, {1}", ex.Message, ex.StackTrace)); } return(loadedTemplate); }
public void SetUp() { LoggerBootstrapper.Initialize(); IoCBootstrapper.Initialize(); }
public void ConfigureContainer(ContainerBuilder builder) { IoCBootstrapper.ConfigureContainer(builder); }
public void SetUp() { LoggerBootstrapper.Initialize(); IoCBootstrapper.Initialize(); new Installer().Install(LifeStyleType.Thread); }
public BaseTest() { this.Container = IoCBootstrapper.GetContainer(); }
/// <summary> /// This method gets called by the runtime. Use this method to add services to the container. /// </summary> /// <param name="services"></param> public IServiceProvider ConfigureServices(IServiceCollection services) { services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); //跨域 services.AddCors(option => { if (!string.IsNullOrEmpty(WebConfig.AppSettings.CorsOrigins)) { var urls = WebConfig.AppSettings.CorsOrigins.Split(','); option.AddPolicy("AllowSameDomain", builder => builder.WithOrigins(urls).AllowAnyMethod().AllowAnyHeader().AllowAnyOrigin()); } else { option.AddPolicy("AllowSameDomain", builder => builder.AllowAnyMethod().AllowAnyHeader().AllowAnyOrigin()); } }); //*注入全局异常捕获*/ services.AddMvc(o => { o.Filters.Add(typeof(GlobalExceptions)); }); //HttpContext服务 services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); //配置文件json注册 services.Configure <ConnectionStrings>(Configuration.GetSection("ConnectionStrings")); services.Configure <JWTSettings>(Configuration.GetSection("Authentication").GetSection("JwtSettings")); services.Configure <AppSettings>(Configuration.GetSection("AppSettings")); services.Configure <ApiSettings>(Configuration.GetSection("ApiSettings")); services.Configure <RedisSettings>(Configuration.GetSection("RedisSetting")); //jwt服务 services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(option => { option.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidateAudience = true, ValidateLifetime = true, ValidateIssuerSigningKey = true, ValidIssuer = WebConfig.JWTSettings.Issuer, ValidAudience = WebConfig.JWTSettings.Audience, IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(WebConfig.JWTSettings.Secret)) }; }); //Swagger services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Info { Title = "My API", Version = "v1", }); var filePath = Path.Combine(AppContext.BaseDirectory, "TestCore.API.xml"); c.IncludeXmlComments(filePath); c.AddSecurityDefinition("Bearer", new ApiKeyScheme { In = "header", Description = "请输入带有Bearer的Token,例如: \"Bearer {token}\"", Name = "Authorization", Type = "apiKey" }); c.AddSecurityRequirement(new Dictionary <string, IEnumerable <string> > { { "Bearer", Enumerable.Empty <string>() } }); }); //批量注册dll return(IoCBootstrapper.Startup(services)); }