本文整理汇总了C#中SimpleInjector.Container.ComposeRoot方法的典型用法代码示例。如果您正苦于以下问题:C# Container.ComposeRoot方法的具体用法?C# Container.ComposeRoot怎么用?C# Container.ComposeRoot使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SimpleInjector.Container
的用法示例。
在下文中一共展示了Container.ComposeRoot方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RegistersDbContext_PropertyInjecting_GreenfieldDbInitializer_Transiently_WhenSettingIsGreenfield
public void RegistersDbContext_PropertyInjecting_GreenfieldDbInitializer_Transiently_WhenSettingIsGreenfield()
{
var container = new Container();
container.ComposeRoot(new RootCompositionSettings { IsGreenfield = true, });
using (container.BeginLifetimeScope())
{
var dbContext = container.GetInstance<EntityDbContext>();
dbContext.Initializer.ShouldNotBeNull();
dbContext.Initializer.ShouldBeType<GreenfieldDbInitializer>();
}
}
示例2: RegistersIDbInitializer_UsingGreenfieldDbInitializer_Transiently_WhenSettingIsGreenfield
public void RegistersIDbInitializer_UsingGreenfieldDbInitializer_Transiently_WhenSettingIsGreenfield()
{
var container = new Container();
container.ComposeRoot(new RootCompositionSettings { IsGreenfield = true, });
var instance = container.GetInstance<IDatabaseInitializer<EntityDbContext>>();
var registration = container.GetRegistration(typeof(IDatabaseInitializer<EntityDbContext>));
instance.ShouldNotBeNull();
instance.ShouldBeType<GreenfieldDbInitializer>();
registration.Lifestyle.ShouldEqual(Lifestyle.Transient);
}
示例3: RegistersICustomizeDb_UsingSqlServerDbCustomizer_Transiently_WhenSettingIsGreenfield
public void RegistersICustomizeDb_UsingSqlServerDbCustomizer_Transiently_WhenSettingIsGreenfield()
{
var container = new Container();
container.ComposeRoot(new RootCompositionSettings { IsGreenfield = true, });
var instance = container.GetInstance<ICustomizeDb>();
var registration = container.GetRegistration(typeof(ICustomizeDb));
instance.ShouldNotBeNull();
instance.ShouldBeType<SqlServerScriptsCustomizer>();
registration.Lifestyle.ShouldEqual(Lifestyle.Transient);
}
示例4: CompositionRootFixture
public CompositionRootFixture()
{
HttpContext.Current = null;
Container = new Container();
var assemblies = new[] { Assembly.GetExecutingAssembly() };
var settings = new RootCompositionSettings
{
FluentValidatorAssemblies = assemblies,
QueryHandlerAssemblies = assemblies,
CommandHandlerAssemblies = assemblies,
};
Container.ComposeRoot(settings);
}
示例5: Configure
public static void Configure()
{
var container = new Container();
var settings = new RootCompositionSettings
{
#if DEBUG
IsGreenfield = true,
#endif
FluentValidatorAssemblies = new[]
{
Assembly.GetAssembly(typeof(IHandleCommand<>)),
Assembly.GetExecutingAssembly(),
},
};
container.ComposeRoot(settings);
container.RegisterMvcControllers(Assembly.GetExecutingAssembly());
container.RegisterMvcAttributeFilterProvider();
container.Verify();
DependencyResolver.SetResolver(new SimpleInjectorDependencyResolver(container));
GlobalConfiguration.Configuration.DependencyResolver = new WebApiDependencyResolver(container);
FluentValidation.Mvc.FluentValidationModelValidatorProvider.Configure(
provider =>
{
provider.ValidatorFactory = new ValidatorFactory(container);
provider.AddImplicitRequiredValidator = false;
}
);
FluentValidation.Mvc.WebApi.FluentValidationModelValidatorProvider.Configure(provider =>
{
provider.ValidatorFactory = new ValidatorFactory(container);
});
}
示例6: ComposeRoot_UsesDefaultSettings_WhenNoneArePassed
public void ComposeRoot_UsesDefaultSettings_WhenNoneArePassed()
{
var container = new Container();
container.ComposeRoot(null);
}
示例7: RegisterDependencies
/// <summary>Initialize the container and register it as MVC3 Dependency Resolver.</summary>
public static void RegisterDependencies()
{
// compose the root
var container = new Container(
new ContainerOptions
{
AllowOverridingRegistrations = true,
});
var rootCompositionSettings = new RootCompositionSettings
{
Flags = RootCompositionFlags.Web |
RootCompositionFlags.Work,
FluentValidationAssemblies = new[]
{
Assembly.GetAssembly(typeof(IHandleCommands<>)),
Assembly.GetExecutingAssembly(),
}
};
container.ComposeRoot(rootCompositionSettings);
container.RegisterMvcControllers(Assembly.GetExecutingAssembly());
container.RegisterMvcAttributeFilterProvider();
container.RegisterHttpFilterProvider();
container.Verify();
DependencyResolver.SetResolver(new SimpleInjectorDependencyResolver(container));
GlobalConfiguration.Configuration.DependencyResolver = new SimpleInjectorHttpDependencyResolver(container);
FluentValidationModelValidatorProvider.Configure(
provider =>
{
provider.ValidatorFactory = new FluentValidationValidatorFactory(container);
provider.AddImplicitRequiredValidator = false;
}
);
// seed data
if (rootCompositionSettings.Flags.HasFlag(RootCompositionFlags.Debug))
{
var seeder = container.GetInstance<ISeedData>();
if (seeder != null) seeder.Seed();
}
// fire up poor man's worker role
if (rootCompositionSettings.Flags.HasFlag(RootCompositionFlags.Work) &&
rootCompositionSettings.Flags.HasFlag(RootCompositionFlags.Debug) &&
!rootCompositionSettings.Flags.HasFlag(RootCompositionFlags.Azure))
{
var cancellationTokenSource = new CancellationTokenSource();
var cancellationToken = cancellationTokenSource.Token;
Task.Factory.StartNew(() =>
{
var workerRole = DependencyResolver.Current.GetService<WebDevelopmentWorkerRole>();
workerRole.OnStart();
workerRole.Run(cancellationToken);
}, cancellationToken);
AppDomain.CurrentDomain.DomainUnload += (sender, args) => cancellationTokenSource.Cancel();
}
}