本文整理汇总了C#中SimpleInjector.Container.AppendToCollection方法的典型用法代码示例。如果您正苦于以下问题:C# Container.AppendToCollection方法的具体用法?C# Container.AppendToCollection怎么用?C# Container.AppendToCollection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SimpleInjector.Container
的用法示例。
在下文中一共展示了Container.AppendToCollection方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RegisterDependencies
public static void RegisterDependencies()
{
var container = new Container {Options = {DefaultScopedLifestyle = new WebRequestLifestyle()}};
// Container
container.Register<IServiceProvider>(() => container);
// Request (command/query) dispatcher
container.Register<IRequestDispatcher, RequestDispatcher>();
// Command handlers
container.Register(typeof (ICommandHandler<>), new[] {typeof (TabService).Assembly});
container.RegisterDecorator(typeof (ICommandHandler<>), typeof (ValidationDecoratorCommandHandler<>));
container.RegisterDecorator(typeof (ICommandHandler<>), typeof (LoggingDecoratorCommandHandler<>));
// Query handlers
container.Register(typeof (IQueryHandler<,>), new[] {typeof (TabReadModel).Assembly});
// Validators
container.RegisterSingleton(typeof (IValidator<>), typeof (CompositeValidator<>));
container.AppendToCollection(typeof (IValidator<>), typeof (DataAnnotationsValidator<>));
container.RegisterCollection(typeof (IValidator<>), typeof (MvcApplication).Assembly);
// Data annotations validators
container.Register(typeof (IValidationAttributeValidator<>), new[] {typeof (IValidationAttributeValidator<>).Assembly});
// Loggers
container.RegisterSingleton<ILoggerFactory, NLogLoggerFactory>();
// Action filters
container.RegisterCollection(typeof (IActionFilter<>), typeof (MvcApplication).Assembly);
// Repository
container.Register<IEventStore, InMemoryEventStore>();
// Aggregate factory
container.Register<IAggregateFactory, AggregateFactory>();
// Event publisher
container.Register<IEventPublisher>(() => new EventPublisher(type => container.GetAllInstances(type), container.GetInstance<ILoggerFactory>()));
// Event handlers
container.RegisterCollection(typeof (IEventSubscriber<>), new[] {typeof (TabReadModel).Assembly});
// View model database
container.RegisterSingleton<IReadModelDatabase, InMemoryReadModelDatabase>();
// Verify
container.Verify();
System.Web.Mvc.DependencyResolver.SetResolver(new SimpleInjectorDependencyResolver(container));
System.Web.Mvc.GlobalFilters.Filters.Add(new ActionFilterDispatcher(type => container.GetAllInstances(type)));
ServiceProvider = container;
}
示例2: AddMapperProfile
/// <summary>
/// Adds the mapper profile.
/// </summary>
/// <param name="container">The container.</param>
private void AddMapperProfile(Container container)
{
try
{
container.AppendToCollection(typeof(Profile),
Lifestyle.Singleton.CreateRegistration(typeof(Profile),
typeof(EntityMapperConfig), container));
}
catch (Exception ex)
{
ex.ExceptionValueTracker(container);
}
}
示例3: RegisterServices
public static void RegisterServices(Container container, ILoggerFactory loggerFactory) {
container.Register<IUserIdProvider, PrincipalUserIdProvider>();
container.Register<MessageBusConnection>();
container.RegisterSingleton<ConnectionMapping>();
container.RegisterSingleton<MessageBusBroker>();
var resolver = new SimpleInjectorSignalRDependencyResolver(container);
container.RegisterSingleton<IDependencyResolver>(resolver);
container.RegisterSingleton<IConnectionManager>(() => new ConnectionManager(resolver));
container.RegisterSingleton<OverageHandler>();
container.RegisterSingleton<ThrottlingHandler>(() => new ThrottlingHandler(container.GetInstance<ICacheClient>(), userIdentifier => Settings.Current.ApiThrottleLimit, TimeSpan.FromMinutes(15)));
container.AppendToCollection(typeof(Profile), typeof(ApiMappings));
}
示例4: 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));
}