simple-injector

What is the correct way to register FluentValidation with SimpleInjector?

拟墨画扇 提交于 2019-12-04 11:48:22
问题 I am able to register FluentValidation AbstractValidators using a FluentValidatorFactory . However, it doesn't feel right, because not all of the IoC container registrations happen during bootstrap / composition root. Instead, the fluent validators are registered by a separate factory: The composition root : public class SimpleDependencyInjector : IServiceProvider { public readonly Container Container; public SimpleDependencyInjector() { Container = Bootstrap(); } internal Container Bootstrap

MassTransit and Simple Injector [closed]

六眼飞鱼酱① 提交于 2019-12-04 11:22:11
I'm reviewing the MassTransit Distributed Application Framework for .NET . According to the website MassTransit has been built from the beginning with the concept of an IoC container being involved and provides support libraries for a handful of the more "mainstream" IoC Containers. There are (currently) NuGet packages available for Autofac, StructureMap, Castle Windsor, Ninject & Unity. I have selected Simple Injector as my IoC container of choice for performance reasons but I am unable to find an integration library adding support for Simple Injector to MassTransit. Has anyone tried this,

Membership reboot replace Ninject with Simple Injector

谁都会走 提交于 2019-12-04 10:36:08
I need add membership reboot (RavenDb) into the project that use IOC Simple Injector Ninject implementation var config = MembershipRebootConfig.Create(); kernel.Bind<MembershipRebootConfiguration<HierarchicalUserAccount>>().ToConstant(config); kernel.Bind<UserAccountService<HierarchicalUserAccount>>().ToSelf(); kernel.Bind<AuthenticationService<HierarchicalUserAccount().To<SamAuthenticationService<HierarchicalUserAccount>>(); kernel.Bind<IUserAccountRepository<HierarchicalUserAccount>>().ToMethod(ctx => new BrockAllen.MembershipReboot.RavenDb.RavenUserAccountRepository("RavenDb")); kernel.Bind

How to check whether DbContext has transaction?

淺唱寂寞╮ 提交于 2019-12-04 03:28:38
Background: I have WCF service with SimpleInjector as IoC which creates instance of DbContext per WCF request. Backend itself is CQRS. CommandHandlers have a lot of decorators (validation, authorization, logging, some common rules for different handler groups etc) and one of them is Transaction Decorator: public class TransactionCommandHandlerDecorator<TCommand> : ICommandHandler<TCommand> where TCommand : ICommand { private readonly ICommandHandler<TCommand> _handler; private readonly IMyDbContext _context; private readonly IPrincipal _principal; public TransactionCommandHandlerDecorator

Simple Injector Register All Services From Namespace

眉间皱痕 提交于 2019-12-04 02:10:01
My Service Interfaces has a namespace of Services.Interfaces The implementation of the Service Interfaces has a namespace of Web.UI.Services I have 2 service implementations for example IUserService which needs to register to UserService ICountryService which needs to register to CountryService This is how I currently register these services with SimpleInjector. container.Register<IUserService, UserService> (); container.Register<ICountryService, CountryService> (); Problem: If I have over 100 services to exaggerate a bit. I need to go and add a line for each service. How can I register all

Using Simple Injector with Umbraco Controller

我的梦境 提交于 2019-12-04 01:30:42
问题 I'm trying to Inject a dependency into a controller which inherits from Umbraco's RenderMvcController and getting the error No registration for type RenderMvcController could be found and an implicit registration could not be made. For the container to be able to create RenderMvcController it should have only one public constructor: it has 3. See https://simpleinjector.org/one-constructor for more information. Below is my code to wire up the DI var container = new Container(); container

Simple injector open generic decorators

Deadly 提交于 2019-12-03 21:18:50
I am trying to make use of some of the nice features in simple injector. I am currently having problems with the decorators, they are not getting hit when I expect them too. I am registering them like this: container.RegisterManyForOpenGeneric( typeof(ICommandHandler<>), AppDomain.CurrentDomain.GetAssemblies()); container.RegisterDecorator( typeof(ICommandHandler<>), typeof(CreateValidFriendlyUrlCommandHandler<>), context => context.ServiceType == typeof(ICommandHandler<CreateProductCommand>) ); container.RegisterDecorator( typeof(ICommandHandler<>), typeof

Prevent Simple Injector to throw an exception when resolving an unregistered service

落爺英雄遲暮 提交于 2019-12-03 16:45:46
I was wondering if Simple Injector has an option to stop throwing exceptions whenever GetInstance(Of TService) returns Nothing ? It appears to be throwing them now because I have two requests to get an instance, it's not there, and it throws the exception. Is there a way to prevent the default behavior, a setting somewhere, or something else? Steven There absolutely is a simple way of doing this. The SimpleInjector.Container implements System.IServiceProvider , which defines an object GetService(Type) method. This method returns null when a type is not registered. The IServiceProvider however,

SimpleInjector and FluentValidationFactory

元气小坏坏 提交于 2019-12-03 16:23:48
I am trying to automate the validation of my view models, I know I can just add a an attribute to specify my validation but there is an option to set up a factory to automate all that, I looked at: this answer and came up with this using simple injector 3.1: public class CustomValidatorFactory:ValidatorFactoryBase { private readonly Container siContainer; public CustomValidatorFactory(Container siContainer) { var assemblies = AppDomain.CurrentDomain.GetAssemblies().ToList(); this.siContainer = siContainer; this.siContainer.Register(typeof(IValidator<>), assemblies); } public override

Injection into Console Application with the Simple Injector

試著忘記壹切 提交于 2019-12-03 13:00:25
问题 I am using Simple Injector for test purpose but prety new on OOP. I am trying to create loosly couple classes. Here is the my scenario. I have User repo and interface like this. public class UserRepository:IUserRepository { public void Add(Model.User user) { Console.WriteLine("Name:"+user.Name+"\n"+"SurName:"+user.SureName); } public void Delete(int id) { throw new NotImplementedException(); } } public interface IUserRepository { void Add(User user); void Delete(int id); } My