autofac

Callback on SaveChanges in EFCore?

五迷三道 提交于 2019-12-24 08:09:13
问题 I'm trying to do something like in my DbContext : public System.Action<IEnumerable<EntityEntry>> OnSave; public override int SaveChanges() { if(OnSave != null) OnSave(ChangeTracker.Entries()); return base.SaveChanges(); } Then DI (AutoFac) the DbContext into another class which can hook into the 'OnSave' function. I'm looking for a single source of truth when this happens. I don't think this will work or be reliable when DbContext is injected into multiple places since I'm pretty sure we end

How to register custom build Autofac.Module in Orchard?

北城余情 提交于 2019-12-24 07:04:02
问题 I have a piece of code that encapsulates functionality that isn't specific to Orchard. However i need to make it available in Orchard via dependency injection. So, I built up an Autofac Module that registers all components (types), but I can't find a way to inform Orchard's Autofac Container about it. From what i red, there are two ways to add a module to a container: By supplying the module at to the ContainerBuilder (usually at start-up), Or by updating the already built Container at

What is the best way to pass runtime constructor parameters to Autofac?

喜你入骨 提交于 2019-12-24 06:57:45
问题 I am building a generic piece of middleware software (a windows service) that will perform many jobs .. such as: Sync Inventory Import Orders etc I am using C# with a Windows Service, and Quartz.NET to schedule the jobs to run. I am also using AutoFac. From what I understand, AutoFac dependencies should be built at the composition root. This is fine..however, I have certain services that get injected which require runtime parameters (configuration values that come from the database). For

Resolving dependencies in XAML using Autofac

北战南征 提交于 2019-12-24 06:47:45
问题 I have a class MyResource in my application that looks like this: public class MyResource : IMyResource { // ... whatever ... } And when I initialize my application in App.xaml.cs I have something like that using Autofac: builder.Register<IMyResource>(container => new MyResource()); Now I need to add a StaticResource in a Window of my WPF application, something like this: <Window.Resources> <local:MyResource x:Key="MyResource" /> </Window.Resources> But of course, the whole idea is not to

Factory with Autofac dependencies

大兔子大兔子 提交于 2019-12-24 03:20:26
问题 I want to write a factory for creating various types of "xxNotification" classes. My concrete "xxNotification" has dependencies registered with AutoFac. I would like to get/resolve instance of "xxNotification" using Autofac. How to do that? public interface INotification { void Notify(string Action, int OrderID); } public class MagentoOrderStateNotification : INotification { private readonly GenericRepository<Order> _orderRepository; private readonly OMRestIntegrationService

Factory with Autofac dependencies

感情迁移 提交于 2019-12-24 03:20:24
问题 I want to write a factory for creating various types of "xxNotification" classes. My concrete "xxNotification" has dependencies registered with AutoFac. I would like to get/resolve instance of "xxNotification" using Autofac. How to do that? public interface INotification { void Notify(string Action, int OrderID); } public class MagentoOrderStateNotification : INotification { private readonly GenericRepository<Order> _orderRepository; private readonly OMRestIntegrationService

Swap out repositories with a flag

断了今生、忘了曾经 提交于 2019-12-24 03:18:35
问题 I have an IRepository< T > interface with many T's and several implementations (on-demand DB, web service, etc.). I use AutoFac to register IRepository's for many T's depending on the kind of repository I want for each T. I also have a .NET-caching-based implementation that looks for T's in cache and then calls a 'real' IRepository.Find to resolve a cache miss. It is constructed something like this: new CachingRepository(realRepository, cacheImplementation); I would like to use a

SignalR Autofac Inject Authorize Attribute

一曲冷凌霜 提交于 2019-12-24 00:27:51
问题 I'm trying to figure out a way to inject dependencies into my AuthorizeAttribute in SignalR similar to the way it is done in WebAPI. In Web API I know I can call builder.RegisterWebApiFilterProvider(config); but I can't quite seem to find an equivalent for SignalR. The closest thing I can find that looks like it might do the trick is the PropertiesAutowired() method. I have tried builder.RegisterType<MyAuthorizationAttribute>.PropertiesAutowired(); where my attribute looks like public class

Visualizing dependency tree depth in autofac

本秂侑毒 提交于 2019-12-23 19:28:12
问题 I may have been searching for the wrong stuff, looking in the wrong boxes. But I can't seem to find a good way to visualize how deep my dependecy tree is in C#. I've initially tried just hooking up on the preparing-event & the activating-event from Autofac. But I can't figure out if this is good enough. The results looks kinda funky. It seems that the preparing-event is initiated too often. And it seems that the activating event is only activated when a new object is actually created. Our

Ioc and WebForms - How to inject properties in user controls

帅比萌擦擦* 提交于 2019-12-23 18:22:45
问题 I am adding IoC to an already existing web forms project, and I am having a little trouble with getting the dependencies of user controls injected, especially dynamic user controls in a master page. On the master page, I load some user controls: protected override void OnLoad(EventArgs e) { bool processComplete = false; var page = Page as BasePage; if (page != null && HttpContext.Current.User.Identity.IsAuthenticated) processComplete = page.processComplete ; var segments = this.Request.Url