fokipro.blogg.se

Masstransit autofac findtypes
Masstransit autofac findtypes







MassTransit adds a hosted service so that the generic host can start and stop the bus (or buses, if multiple bus instances are configured). To configure multiple bus instances in the same service collection, refer to the MultiBus section. Health checks for the bus (or buses) and receive endpoints.The bus endpoint with the default settings (not started by default).Several interfaces (and their implementations, appropriate for the transport specified).Any methods to configure the bus instance (using x) should be called outside of this callback.Īdding MassTransit, as shown above, will configure the service collection with required components, including: SchemaAction(圜) Īll thats left is to register your saga builder.RegisterType().The callback passed to the UsingRabbitMq method is invoked after the service collection has been built. Now wire that builder.Register(c => SagaPersistenceHandler.CreateSessionFactory()).As() Īnd the saga mapping to the saga (not included) public MySagaMap() Var provider = new SqlServerSessionFactoryProvider(, new Public static ISessionFactory CreateSessionFactory() Then wire it builder.RegisterGeneric(typeof(NHibernateSagaRepository)).Named("innerRepo", typeof(ISagaRepository)) īuilder.RegisterGenericDecorator(typeof(MySagaRepository), typeof(ISagaRepository), fromKey: "innerRepo") įor the persistance it was just a matter of public class SagaPersistenceHandler Public IEnumerable Select(Func transformer) Public IEnumerable Where(ISagaFilter filter, Func transformer) Public IEnumerable Where(ISagaFilter filter) Public IEnumerable Find(ISagaFilter filter) Return _inner.GetSaga(context, sagaId, (saga, message) => Public IEnumerable> GetSaga(IConsumeContext context, Guid sagaId, InstanceHandlerSelector selector, ISagaPolicy policy) where TMessage : class Public MySagaRepository(ISagaRepository inner, IComponentContext context) Private readonly IComponentContext _context Old question but it took a while for us to figure out a suitable way to wiring up sagas and autofac and then adding nhibernate on top of that.įirst create a wiring class (property injection) public class MySagaRepository : ISagaRepository where TSaga : class, ISaga I've got a workaround for my current issue, but I'll post an answer here if/when I find one. Given it's NHibernate that's hydrating the object I should be looking there for the hook. Here is the example of the injecting repository for Magnum:

masstransit autofac findtypes

There are a couple of helper classes that can be used to perform property-injection into the saga after it is loaded from NHibernate, the decorating saga repository I think has been posted here.

masstransit autofac findtypes

Injecting dependencies into a class hydrated via NHibernate is never going to end well. I got a reply from Chris Patterson on the masstransit-discuss group that pointed out I was probably doing it wrong.Īutomatonymous is a better choice if you have dependencies, since the state machine and the state itself are separate classes. OnActivated(arg => =Īny help on what I'm doing wrong would be appreciated. I also tried using property injection with no luck: builder.RegisterAssemblyTypes(assembly) I've tried adding the Func to a constructor, but it's not hit, it does work in a consumer so I know Autofac can build a Func. The saga itself is pretty standard public class MySaga : SagaStateMachine, ISaga Sbc.Subscribe(cfg => cfg.LoadFrom(scope)) HostConfig.SetPassword(ConfigurationManager.AppSettings) HostConfig.SetUsername(ConfigurationManager.AppSettings) TransportConfig.ConfigureHost(queueUri, hostConfig => Var queueUri = new Uri(ConfigurationManager.AppSettings) Register(context => ServiceBusFactory.New(sbc => RegisterGeneric(typeof(NHibernateSagaRepository)) Where(type => type.IsAssignableTo() || type.IsAssignableTo()) Where(type => type.Implements(typeof(SagaClassMapping))) īuilder.Register(context => GetSessionFactory(mapTypes)).AsSelf().SingleInstance()

#Masstransit autofac findtypes registration#

Here's my registration code: var mapTypes = assembly.GetTypes()

masstransit autofac findtypes

I've had no problem injecting the factory into a consumer so I know it's registered correctly, so I'm assuming I'm not registering the sagas correctly and autofac isn't building them up. I'm trying to get autofac to inject an factory into a saga on creation, and I can't get it working.







Masstransit autofac findtypes