本文整理汇总了C#中SimpleInjector.Container.AddRegistration方法的典型用法代码示例。如果您正苦于以下问题:C# Container.AddRegistration方法的具体用法?C# Container.AddRegistration怎么用?C# Container.AddRegistration使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SimpleInjector.Container
的用法示例。
在下文中一共展示了Container.AddRegistration方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConfigContainer
public static void ConfigContainer(Container container)
{
#region - MAPPER -
var mapperConfig = AutoMapperConfig.GetMapperConfiguration();
container.RegisterSingleton<IConfigurationProvider>(mapperConfig);
container.Register(() => mapperConfig.CreateMapper());
container.Register<IMapperAdapter, AutoMapperAdapter>();
#endregion
#region - CONTEXTS -
container.Register<DbContext, CoreContext>(Lifestyle.Scoped);
#endregion
#region - REPOSITORIES -
container.Register<IClientRepository, ClientRepository>(Lifestyle.Scoped);
container.Register<IRefreshTokenRepository, RefreshTokenRepository>(Lifestyle.Scoped);
container.Register<IUsuarioRepository, UsuarioRepository>(Lifestyle.Scoped);
#endregion
#region - DOMAINS -
var registration = Lifestyle.Scoped.CreateRegistration<UsuarioDomain>(container);
container.AddRegistration(typeof(IUsuarioDomain), registration);
container.AddRegistration(typeof(IUserStore<Usuario, long>), registration);
container.Register<UserManager<Usuario, long>>(Lifestyle.Scoped);
container.Register<IRefreshTokenDomain, RefreshTokenDomain>(Lifestyle.Scoped);
container.Register<IClientDomain, ClientDomain>(Lifestyle.Scoped);
container.Register<IAccountDomain, AccountDomain>(Lifestyle.Scoped);
#endregion
}
示例2: RegisterServices
public void RegisterServices(Container container)
{
// Required: How to instantiate the DbContext; and share it amongst objects participating in a single request.
var webApiRequestLifestyle = new WebApiRequestLifestyle(true);
var hybridLifestyle = Lifestyle.CreateHybrid(() => webApiRequestLifestyle.GetCurrentScope(container) == null, Lifestyle.Transient, webApiRequestLifestyle);
container.Register(() =>
{
var db = new ScrumDb();
db.AttachDbEnums();
return db;
},
hybridLifestyle);
container.RegisterLazy<ScrumDb>();
// Required: Register global datamodel metadata
var metadataRegistration = hybridLifestyle.CreateRegistration<DbContextMetadata<ScrumDb>>(container);
container.AddRegistration(typeof(IContainerMetadata<ScrumDb>), metadataRegistration);
container.AddRegistration(typeof(IContainerMetadata), metadataRegistration);
// Query validation settings could be specified here
//container.RegisterInstance(new ODataValidationSettings
//{
// MaxExpansionDepth = 15,
// MaxTop = 200
//}); //.Named<ODataValidationSettings>("Edit"); TODO: Figure out how to separate ODataValidationSettings for Edit controllers vs ReadOnly controllers
}
示例3: RegisterServices
/// <summary>
/// Registers application-level IoC settings.
/// </summary>
/// <param name="container"></param>
public void RegisterServices(Container container)
{
container.RegisterWebApiRequestOrTransient<TodoListContext>();
container.RegisterLazy<TodoListContext>();
// Required: Register global datamodel metadata (IContainerMetadata and IContainerMetadata<DbContext>)
var mmRegistration = Lifestyle.Singleton.CreateRegistration(() => new DbContextMetadata<TodoListContext>(new TodoListContext()), container);
container.AddRegistration(typeof(IContainerMetadata), mmRegistration);
container.AddRegistration(typeof(IContainerMetadata<TodoListContext>), mmRegistration);
// Query validation settings could be specified here
container.RegisterSingleton(new ODataValidationSettings()
{
MaxExpansionDepth = 5
});
}
示例4: Configuration
public void Configuration(IAppBuilder app)
{
var container = new Container();
var registration = Lifestyle.Transient.CreateRegistration
(
typeof(ChatHub),
() => new ChatHub(new ChatService()),
container
);
container.AddRegistration(typeof(ChatHub), registration);
registration.SuppressDiagnosticWarning
(
DiagnosticType.DisposableTransientComponent,
"Ignoring IDisposable for transient hubs"
);
container.Verify();
var config = new HubConfiguration()
{
Resolver = new ChatHubDependencyResolver(container)
};
app.MapSignalR(config);
}
示例5: RegisterServices
public void RegisterServices(Container container)
{
var serviceAssemblies = new[]
{
typeof(IService).Assembly,
Assembly.Load(AssemblyConstants.ServicesData),
Assembly.Load(AssemblyConstants.ServicesAdministration),
};
var registrations = serviceAssemblies
.SelectMany(a => a.GetExportedTypes())
.Where(t => typeof(IService).IsAssignableFrom(t) && !t.IsAbstract && !t.IsGenericTypeDefinition)
.Select(t => new { Service = t.GetInterfaces().Single(i => i != typeof(IService)), Implementation = t })
.ToList();
var webRequestLifestyle = new WebRequestLifestyle();
foreach (var registration in registrations)
{
container.AddRegistration(
registration.Service,
webRequestLifestyle.CreateRegistration(registration.Service, registration.Implementation, container));
}
//// TODO: Register with LINQ!
////container.Register<ICacheService, HttpRuntimeCacheService>(webRequestLifestyle);
////container.Register<ICacheItemsProviderService, CacheItemsProviderService>(webRequestLifestyle);
////container.Register<ITagsDataService, TagsDataService>(webRequestLifestyle);
////container.Register<IPostsDataService, PostsDataService>(webRequestLifestyle);
////container.Register<ICommentsDataService, CommentsDataService>(webRequestLifestyle);
}
示例6: Setup
public static void Setup()
{
var container = new Container();
var perRequest = new WebRequestLifestyle();
var dataAccessAssembly = typeof(CinemaContext).Assembly;
var moviesAssembly = typeof(Seat).Assembly;
var promotionsAssembly = typeof(Promotions.Promotion).Assembly;
var applicationAssembly = typeof(RenamePromotionCommand).Assembly;
var connectionString = ConfigurationManager.ConnectionStrings["DDDCinema"].ConnectionString;
container.Register(() => new CinemaContext(connectionString), perRequest);
container.Register(() => new PromotionsContext(connectionString), perRequest);
container.Register(() => new InfrastructureContext(connectionString), perRequest);
container.Register(() => new DDDCinemaReadonly(), perRequest);
var userProviderRegistration = Lifestyle.Singleton.CreateRegistration<ContextUserProvider>(container);
container.AddRegistration(typeof(ICurrentUserProvider), userProviderRegistration);
container.AddRegistration(typeof(ContextUserProvider), userProviderRegistration);
container.Register<IWinChanceCalculatorFactory, SimpleInjectorWinChanceCalculatorFactory>(Lifestyle.Singleton);
foreach (var repositorType in dataAccessAssembly.GetExportedTypes()
.Where(t => t.Name.Contains("Repository")))
{
container.Register(repositorType.GetInterfaces().Single(), repositorType, perRequest);
}
container.RegisterDecorator(typeof(ICommandHandler<LoginCommand>), typeof(AuditingLoginCommandHandler));
container.RegisterDecorator(typeof(ICommandHandler<>), typeof(AuditingCommandHandler<>),
p => !p.AppliedDecorators.Any(t => t.Name.Contains("Auditing")));
container.RegisterDecorator(typeof(ICommandHandler<>), typeof(CinemaTransactionalCommandHandler<>));
container.RegisterDecorator(typeof(ICommandHandler<>), typeof(PromotionTransactionalCommandHandler<>));
container.RegisterDecorator(typeof(ICommandHandler<>), typeof(InfrastructureTransactionalCommandHandler<>));
container.Register(typeof(ICommandHandler<>), new[] { applicationAssembly });
container.RegisterCollection(typeof(INotificationSender), new[] { moviesAssembly });
var registration = perRequest.CreateRegistration<SendNotificationWhenSeatTaken>(container);
container.AppendToCollection(typeof(IDomainEventHandler<>), typeof(AuditOccurrenceEventHandler<>));
container.RegisterCollection(typeof(IDomainEventHandler<>), moviesAssembly, promotionsAssembly);
container.RegisterDecorator(typeof(IDomainEventHandler<>), typeof(AuditingEventHandler<>),
p => !p.ImplementationType.Name.Contains("Audit"));
container.Register<List<INotificationSender>>(() => container.GetAllInstances<INotificationSender>().ToList(), perRequest);
container.Register<ISheduler, SagaTimeoutSheduler>(perRequest);
container.Register<IPromotionCodeGenerator, PromoCodeGenerator>(perRequest);
DomainEventBus.Current = new SimpleInjectorEventBus(container);
DependencyResolver.SetResolver(new SimpleInjectorDependencyResolver(container));
}
示例7: RegisterServices
/// <summary>
/// Registers application-level IoC settings.
/// </summary>
/// <param name="container"></param>
public void RegisterServices(Container container)
{
container.RegisterWebApiRequestOrTransient<ScrumDb>();
container.RegisterLazy<ScrumDb>();
// Required: Register global datamodel metadata (IContainerMetadata and IContainerMetadata<DbContext>)
var mmRegistration = Lifestyle.Singleton.CreateRegistration(() => new DbContextMetadata<ScrumDb>(new ScrumDb()), container);
container.AddRegistration(typeof(IContainerMetadata), mmRegistration);
container.AddRegistration(typeof(IContainerMetadata<ScrumDb>), mmRegistration);
// Query validation settings could be specified here
container.RegisterSingleton(new ODataValidationSettings()
{
MaxExpansionDepth = 5,
MaxTop = 200
}); //.Named<ODataValidationSettings>("Edit"); TODO: Figure out how to separate ODataValidationSettings for Edit controllers vs ReadOnly controllers
}
示例8: RegisterServices
public void RegisterServices(Container container)
{
container.RegisterWebApiRequestOrTransient<EStoreDb>();
container.RegisterLazy<EStoreDb>();
// Required: Register global datamodel metadata
var mmRegistration = Lifestyle.Singleton.CreateRegistration<DbContextMetadata<EStoreDb>>(container);
container.AddRegistration(typeof(IContainerMetadata), mmRegistration);
container.AddRegistration(typeof(IContainerMetadata<EStoreDb>), mmRegistration);
// Query validation settings could be specified here
container.RegisterSingleton(new ODataValidationSettings()
{
MaxExpansionDepth = 5,
MaxTop = 200
});
}
示例9: RegisterServices
/// <summary>
/// Registers application-level IoC settings.
/// </summary>
/// <param name="container"></param>
public void RegisterServices(Container container)
{
// Support sharing the DbContext amongst objects participating in a single request;
// but if there is no request, just make it transient.
var webApiRequestLifestyle = new WebApiRequestLifestyle(true);
var hybridLifestyle = Lifestyle.CreateHybrid(() => webApiRequestLifestyle.GetCurrentScope(container) == null, Lifestyle.Transient, webApiRequestLifestyle);
container.Register<TodoListContext>(hybridLifestyle);
container.RegisterLazy<TodoListContext>();
// Required: Register global datamodel metadata (IContainerMetadata and IContainerMetadata<DbContext>)
var mmRegistration = Lifestyle.Singleton.CreateRegistration<DbContextMetadata<TodoListContext>>(container);
container.AddRegistration(typeof(IContainerMetadata), mmRegistration);
container.AddRegistration(typeof(IContainerMetadata<TodoListContext>), mmRegistration);
// Query validation settings could be specified here
container.RegisterSingle(new ODataValidationSettings()
{
MaxExpansionDepth = 5,
MaxTop = 200
});
}
示例10: Configuration
public void Configuration(IAppBuilder app)
{
ConfigureAuth(app);
// scan assemblies for types
var currentAssembly = typeof(Startup).Assembly;
var componentMap = AutoRegistration.GetComponentMap(currentAssembly
, x => typeof(IController).IsAssignableFrom(x)
, currentAssembly
, x => x.IsInterface);
// init conventions for automapper
StaticAutoMapperWrapper.Init(cfg =>
{
ConventionalProfile.Scan(currentAssembly);
cfg.AddProfile<ConventionalProfile>();
});
// init IOC-container
var container = new Container();
container.Options.DefaultScopedLifestyle = new WebRequestLifestyle();
var am = Lifestyle.Singleton.CreateRegistration(() => new StaticAutoMapperWrapper(), container);
container.AddRegistration(typeof(IProjector), am);
container.AddRegistration(typeof(IMapper), am);
// Fake Context
var reg = Lifestyle.Singleton.CreateRegistration(() => new FakeContext(new[] {
new Product()
{
Category = new Category()
{
Rating = 100500
},
Id = 1,
Name = "1 Product",
Price = 100500,
}
, new Product()
{
Category = new Category(),
Id = 2,
Name = "2 Product",
Price = 200500
}
}), container);
container.AddRegistration(typeof(ILinqProvider), reg);
container.AddRegistration(typeof(IUnitOfWork), reg);
foreach (var kv in componentMap)
{
container.Register(kv.Key, kv.Value, Lifestyle.Scoped);
}
// This is an extension method from the integration package.
container.RegisterMvcControllers(Assembly.GetExecutingAssembly());
container.Verify();
DependencyResolver.SetResolver(new SimpleInjectorDependencyResolver(container));
}