![]() ![]() 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: 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. 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() Here's my registration code: var mapTypes = assembly.GetTypes() ![]() ![]() 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. The second important thing to remember is that the behavior is completely different when you publish your application.I'm trying to get autofac to inject an factory into a saga on creation, and I can't get it working. This only works in Development so if you created and used a different environment during development the assets are not loaded. So that explains some of the issues that people encountered. To support assets in other environments when running from build output, call UseStaticWebAssets on the host builder in Program.cs: When running the app that uses the RCL from build output ( dotnet run), static web assets are enabled that allow ASP.NET Core to load static web assets from locations outside the Core will load the assets directly from the RCL NuGet location.īy default this is only enabled in the Development environment. The development environmentįirst of all it is important to understand that the behavior of RCL is different in Development compared to other environments. So this blog post is here to explain my findings. I never had time to really investigate the root cause until now. I blogged about RCL before and although I really like the feature I got feedback from my development teams that the behavior was not consistent and they sometimes couldn’t get it working. With RCL you can package Razor views, pages, Razor components and view components and reuse them in different applications. One ASP.NET Core feature that I really like and most people are not aware of it existence are Razor Class libraries(RCL). ![]()
0 Comments
Leave a Reply. |