本文整理汇总了C#中EarlyLearningCenter.GetService方法的典型用法代码示例。如果您正苦于以下问题:C# EarlyLearningCenter.GetService方法的具体用法?C# EarlyLearningCenter.GetService怎么用?C# EarlyLearningCenter.GetService使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EarlyLearningCenter
的用法示例。
在下文中一共展示了EarlyLearningCenter.GetService方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Can_get_state_manager
public void Can_get_state_manager()
{
using (var context = new EarlyLearningCenter())
{
var stateManger = context.GetService<IStateManager>();
Assert.Same(stateManger, context.ChangeTracker.GetInfrastructure());
}
}
示例2: Can_get_replaced_singleton_service_from_scoped_configuration
public void Can_get_replaced_singleton_service_from_scoped_configuration()
{
var provider = new ServiceCollection()
.AddEntityFramework()
.GetInfrastructure()
.AddSingleton<IEntityMaterializerSource, FakeEntityMaterializerSource>()
.BuildServiceProvider();
using (var context = new EarlyLearningCenter(provider))
{
Assert.IsType<FakeEntityMaterializerSource>(context.GetService<IEntityMaterializerSource>());
}
}
示例3: Replaced_services_are_scoped_appropriately
public void Replaced_services_are_scoped_appropriately()
{
var services = new ServiceCollection();
services
.AddEntityFramework()
.GetInfrastructure()
.AddSingleton<IModelSource, FakeModelSource>()
.AddScoped<IStateManager, FakeStateManager>();
var provider = services.BuildServiceProvider();
var context = new EarlyLearningCenter(provider);
var modelSource = context.GetService<IModelSource>();
context.Dispose();
context = new EarlyLearningCenter(provider);
var stateManager = context.GetService<IStateManager>();
Assert.Same(stateManager, context.GetService<IStateManager>());
Assert.Same(modelSource, context.GetService<IModelSource>());
context.Dispose();
context = new EarlyLearningCenter(provider);
Assert.NotSame(stateManager, context.GetService<IStateManager>());
Assert.Same(modelSource, context.GetService<IModelSource>());
context.Dispose();
}
示例4: Can_set_known_context_scoped_services_using_type_activation
public void Can_set_known_context_scoped_services_using_type_activation()
{
var services = new ServiceCollection()
.AddScoped<IStateManager, FakeStateManager>();
var provider = TestHelpers.Instance.CreateServiceProvider(services);
using (var context = new EarlyLearningCenter(provider))
{
Assert.IsType<FakeStateManager>(context.GetService<IStateManager>());
}
}
示例5: Can_set_known_singleton_services_using_type_activation
public void Can_set_known_singleton_services_using_type_activation()
{
var services = new ServiceCollection()
.AddSingleton<IModelSource, FakeModelSource>();
var provider = TestHelpers.Instance.CreateServiceProvider(services);
using (var context = new EarlyLearningCenter(provider))
{
Assert.IsType<FakeModelSource>(context.GetService<IModelSource>());
}
}
示例6: Can_set_known_singleton_services_using_instance_sugar
public void Can_set_known_singleton_services_using_instance_sugar()
{
var modelSource = Mock.Of<IModelSource>();
var services = new ServiceCollection()
.AddInstance(modelSource);
var provider = TestHelpers.Instance.CreateServiceProvider(services);
using (var context = new EarlyLearningCenter(provider))
{
Assert.Same(modelSource, context.GetService<IModelSource>());
}
}
示例7: Can_replace_already_registered_service_with_new_service
public void Can_replace_already_registered_service_with_new_service()
{
var factory = Mock.Of<IOriginalValuesFactory>();
var serviceCollection = new ServiceCollection();
serviceCollection.AddEntityFramework();
serviceCollection.AddInstance(factory);
var provider = serviceCollection.BuildServiceProvider();
using (var context = new EarlyLearningCenter(provider))
{
Assert.Same(factory, context.GetService<IOriginalValuesFactory>());
}
}
示例8: Can_start_with_custom_services_by_passing_in_base_service_provider
public void Can_start_with_custom_services_by_passing_in_base_service_provider()
{
var factory = Mock.Of<IOriginalValuesFactory>();
var serviceCollection = new ServiceCollection()
.AddSingleton<IDbSetFinder, DbSetFinder>()
.AddSingleton<IDbSetSource, DbSetSource>()
.AddSingleton<IEntityMaterializerSource, EntityMaterializerSource>()
.AddSingleton<IMemberMapper, MemberMapper>()
.AddSingleton<IFieldMatcher, FieldMatcher>()
.AddSingleton<DatabaseProviderSelector>()
.AddScoped<IDbSetInitializer, DbSetInitializer>()
.AddScoped<IDbContextServices, DbContextServices>()
.AddLogging()
.AddInstance(factory);
var provider = serviceCollection.BuildServiceProvider();
using (var context = new EarlyLearningCenter(provider))
{
Assert.Same(factory, context.GetService<IOriginalValuesFactory>());
}
}
示例9: Can_get_singleton_service_from_scoped_configuration
public void Can_get_singleton_service_from_scoped_configuration()
{
using (var context = new EarlyLearningCenter())
{
Assert.IsType<StateManager>(context.GetService<IStateManager>());
}
}
示例10: Default_context_scoped_services_are_registered_when_parameterless_constructor_used
public void Default_context_scoped_services_are_registered_when_parameterless_constructor_used()
{
using (var context = new EarlyLearningCenter())
{
Assert.IsType<InternalEntityEntryFactory>(context.GetService<IInternalEntityEntryFactory>());
}
}
示例11: Default_services_are_registered_when_parameterless_constructor_used
public void Default_services_are_registered_when_parameterless_constructor_used()
{
using (var context = new EarlyLearningCenter())
{
Assert.IsType<KeyValueFactorySource>(context.GetService<IKeyValueFactorySource>());
}
}
示例12: TrackGraph_does_not_call_DetectChanges
public void TrackGraph_does_not_call_DetectChanges()
{
var provider = TestHelpers.Instance.CreateServiceProvider(new ServiceCollection().AddScoped<IChangeDetector, ChangeDetectorProxy>());
using (var context = new EarlyLearningCenter(provider))
{
var changeDetector = (ChangeDetectorProxy)context.GetService<IChangeDetector>();
changeDetector.DetectChangesCalled = false;
context.ChangeTracker.TrackGraph(CreateSimpleGraph(2), e => e.Entry.State = EntityState.Unchanged);
Assert.False(changeDetector.DetectChangesCalled);
context.ChangeTracker.DetectChanges();
Assert.True(changeDetector.DetectChangesCalled);
}
}