本文整理汇总了C#中SimpleInjector.Container.BeginExecutionContextScope方法的典型用法代码示例。如果您正苦于以下问题:C# Container.BeginExecutionContextScope方法的具体用法?C# Container.BeginExecutionContextScope怎么用?C# Container.BeginExecutionContextScope使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SimpleInjector.Container
的用法示例。
在下文中一共展示了Container.BeginExecutionContextScope方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConfigureSimpleInjector
//Register Container for classes that use dependecy Injection
private Container ConfigureSimpleInjector(IAppBuilder app)
{
var container = new Container();
container.Options.DefaultScopedLifestyle = new ExecutionContextScopeLifestyle();
container.Register<IUserStore<User, int>, UserStore>(Lifestyle.Scoped);
container.Register<IDatabaseFactory, DatabaseFactory>(Lifestyle.Scoped);
container.Register<IUnitOfWork, UnitOfWork>();
container.Register<IAuthRepository, AuthRepository>();
container.Register<ICommentRepository, CommentRepository>();
container.Register<IUserRepository, UserRepository>();
container.Register<ICompanyProfileRepository, CompanyProfileRepository>();
container.Register<IInsuranceAgentProfileRepository, InsuranceAgentProfileRepository>();
container.Register<ILeadProductRepository, LeadProductRepository>();
container.Register<ILeadTransactionRepository, LeadTransactionRepository>();
container.Register<IReviewPostRepository, ReviewPostRepository>();
app.Use(async (context, next) => {
using (container.BeginExecutionContextScope())
{
await next();
}
});
container.Verify();
return container;
}
示例2: UseOwinContextInjector
public static void UseOwinContextInjector(this IAppBuilder app, Container container)
{
// Create an OWIN middleware to create an execution context scope
app.Use(async (context, next) =>
{
using (var scope = container.BeginExecutionContextScope())
{
await next.Invoke();
}
});
}
示例3: UseSimpleInjectorAspNetRequestScoping
/// <summary>Wraps an ASP.NET request in a execution context scope.</summary>
/// <param name="applicationBuilder">The ASP.NET application builder instance that references all
/// framework components.</param>
/// <param name="container"></param>
public static void UseSimpleInjectorAspNetRequestScoping(this IApplicationBuilder applicationBuilder,
Container container)
{
Requires.IsNotNull(applicationBuilder, nameof(applicationBuilder));
Requires.IsNotNull(container, nameof(container));
applicationBuilder.Use(async (context, next) =>
{
using (container.BeginExecutionContextScope())
{
await next();
}
});
}
示例4: ConfigureDependencies
public static void ConfigureDependencies(HttpConfiguration config, IAppBuilder app)
{
var container = new Container();
container.Options.DefaultScopedLifestyle = new ExecutionContextScopeLifestyle();
container.RegisterWebApiControllers(GlobalConfiguration.Configuration);
ConfigContainer(container);
container.Verify();
app.Use(async (context, next) =>
{
using (container.BeginExecutionContextScope())
{
await next();
}
});
config.DependencyResolver = new SimpleInjectorWebApiDependencyResolver(container);
}
示例5: Configuration
public void Configuration(IAppBuilder app)
{
// For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=316888
//See here:
//https://chanmingman.wordpress.com/2015/01/01/implement-ssl-in-self-hosted-web-api/
//https://pfelix.wordpress.com/2012/02/26/enabling-https-with-self-hosted-asp-net-web-api/
//https://katanaproject.codeplex.com/discussions/545123
var config = new HttpConfiguration();
config.Routes.MapHttpRoute("DefaultApi", "1.0/{controller}/{id}", new { id = RouteParameter.Optional });
app.UseWebApi(config);
var container = new Container();
container.Options.DefaultScopedLifestyle = new ExecutionContextScopeLifestyle();
container.RegisterSingleton(Mapper.Engine);
container.Register<IAnime, Anime>();
container.Register<IAnimeOriginalJson, AnimeOriginalJson>();
container.Register<IAnimeFactory, AnimeFactory>(Lifestyle.Singleton);
container.Register<IAnimeRetriever, AnimeRetriever>(Lifestyle.Singleton);
container.Register<IMappingToJson, MappingToJson>(Lifestyle.Singleton);
container.Register<IAnimeHandler, AnimeHandler>(Lifestyle.Singleton);
container.Register<ICacheHandler, CacheHandler>(Lifestyle.Singleton);
container.RegisterWebApiControllers(config);
container.Verify();
config.DependencyResolver = new SimpleInjectorWebApiDependencyResolver(container);
app.Use(async (context, next) =>
{
using (container.BeginExecutionContextScope())
{
await next();
}
});
}
示例6: SimpleInjectorScope
public SimpleInjectorScope(Container container)
{
_container = container;
_container.BeginExecutionContextScope();
}
示例7: ConfigureSimpleInjector
// Register containers for classes that use dependency injection
private Container ConfigureSimpleInjector(IAppBuilder app)
{
var container = new Container();
container.Options.DefaultScopedLifestyle = new ExecutionContextScopeLifestyle();
container.Register<IUserStore<User, int>, UserStore>(Lifestyle.Scoped);
container.Register<IAuthRepository, AuthRepository>(Lifestyle.Scoped);
container.Register<IDatabaseFactory, DatabaseFactory>(Lifestyle.Scoped);
container.Register<IUnitOfWork, UnitOfWork>();
container.Register<IBlogRepository, BlogRepository>();
container.Register<IPostRepository, PostRepository>();
container.Register<IUserRepository, UserRepository>();
container.Register<IExternalLoginRepository, ExternalLoginRepository>();
container.Register<IBlogService, BlogService>();
container.Register<IWordPressBlogReader, WordPressBlogReader>();
//container.RegisterConditional(
// typeof(ILogger),
// c => typeof(Logger).MakeGenericType(c.Consumer.ImplementationType),
// Lifestyle.Transient,
// c => true);
app.Use(async (context, next) =>
{
using (container.BeginExecutionContextScope())
{
await next();
}
});
container.Verify();
return container;
}
示例8: ConfigureAuth
// For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
public void ConfigureAuth(IAppBuilder app)
{
var container = new Container();
container.Options.DefaultScopedLifestyle = new ExecutionContextScopeLifestyle();
container.Register<IUserIdentityApplicationService, UserIdentityApplicationService>(Lifestyle.Scoped);
container.Verify();
app.Use(
async (context, next) =>
{
using (container.BeginExecutionContextScope())
{
await next();
}
});
// Configure the db context, user manager and signin manager to use a single instance per request
AppBuilderExtensions.CreatePerOwinContext(app, () => new ApplicationDbContext());
//app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
//app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create);
AppBuilderExtensions.CreatePerOwinContext<ApplicationUserManager>(app, ApplicationUserManager.Create);
AppBuilderExtensions.CreatePerOwinContext<ApplicationSignInManager>(app, ApplicationSignInManager.Create);
var securityStampValidator = new SecurityStampValidator(null, null);
// Enable the application to use a cookie to store information for the signed in user
// and to use a cookie to temporarily store information about a user logging in with a third party login provider
// Configure the sign in cookie
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = AuthenticationType.ApplicationCookie,
LoginPath = new PathString("/Account/Login"),
Provider = new CookieAuthenticationProvider
{
// Enables the application to validate the security stamp when the user logs in.
// This is a security feature which is used when you change a password or add an external login to your account.
OnValidateIdentity = securityStampValidator.OnValidateIdentity
}
});
app.UseExternalSignInCookie(AuthenticationType.ExternalCookie);
// Enables the application to temporarily store user information when they are verifying the second factor in the two-factor authentication process.
app.UseTwoFactorSignInCookie(AuthenticationType.TwoFactorCookie, TimeSpan.FromMinutes(5));
// Enables the application to remember the second login verification factor such as phone or email.
// Once you check this option, your second step of verification during the login process will be remembered on the device where you logged in from.
// This is similar to the RememberMe option when you log in.
app.UseTwoFactorRememberBrowserCookie(AuthenticationType.TwoFactorRememberBrowserCookie);
// Uncomment the following lines to enable logging in with third party login providers
//app.UseMicrosoftAccountAuthentication(
// clientId: "",
// clientSecret: "");
//app.UseTwitterAuthentication(
// consumerKey: "",
// consumerSecret: "");
//app.UseFacebookAuthentication(
// appId: "",
// appSecret: "");
//app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
//{
// ClientId = "",
// ClientSecret = ""
//});
}