autofac

Autofac property injection in base class

左心房为你撑大大i 提交于 2021-01-27 06:12:32
问题 I am working on a Windows Phone 8.1 application and I have a base class with public property. public class ViewModelBase { public ISomeClass MyProp {get;set;} } My derived class looks like this public class MainViewModel : ViewModelBase { private readonly INavigation _navigation; public MainViewModel(INavigation navigation) { _navigation = navigation; } } In my App.cs I have var builder = new ContainerBuilder(); builder.RegisterType<Navigation>().As<INavigation>(); builder.RegisterType

Send messages via SignalR HubContext from method in project outside where Hubs are located

▼魔方 西西 提交于 2021-01-04 05:39:30
问题 I have a WebAPI project where the API, Service and Data layers are all in separate projects of the same solution. As part of a method in my Service project, I want to send a message to the connected clients of a hub in the API project. So far all of the examples I have found have everything in a single project and use a controller as the example sending a message via a hub. I've tried dependency injection (Autofac) however I am unable to get a reference to the MessageHub. [HubName("messages")

ASP.NET Core MediatR error: Register your handlers with the container

别说谁变了你拦得住时间么 提交于 2020-12-29 02:47:07
问题 I have a .Net Core app where i use the .AddMediatR extension to register the assembly for my commands and handlers following a CQRS approach. In ConfigureServices in Startup.cs i have used the extension method from the official package MediatR.Extensions.Microsoft.DependencyInjection with the following parameter: services.AddMediatR(typeof(AddEducationCommand).GetTypeInfo().Assembly); The command and commandhandler classes are as follow: AddEducationCommand.cs public class AddEducationCommand

ASP.NET Core MediatR error: Register your handlers with the container

拈花ヽ惹草 提交于 2020-12-29 02:46:37
问题 I have a .Net Core app where i use the .AddMediatR extension to register the assembly for my commands and handlers following a CQRS approach. In ConfigureServices in Startup.cs i have used the extension method from the official package MediatR.Extensions.Microsoft.DependencyInjection with the following parameter: services.AddMediatR(typeof(AddEducationCommand).GetTypeInfo().Assembly); The command and commandhandler classes are as follow: AddEducationCommand.cs public class AddEducationCommand

Autofac injection of IHubContext SignalR MVC

一曲冷凌霜 提交于 2020-12-26 08:09:33
问题 I am trying to get SignalR working with Autofac. I have a repo of a stripped back version of what I have done here: https://github.com/justsayno/signalr-autofac This is adapted from which works using GlobalHost : https://github.com/sstorie/experiments/tree/master/angular2-signalr That works just fine using hte GlobalHost object. I have attempted to follow the documentation on Autofac's site about how to inject SignalR services but I cannot get it to work. This is my config file for

从壹开始前后端分离【 .NET Core2.2/3.0 +Vue2.0 】框架之九 || 依赖注入IoC学习 + AOP界面编程初探

佐手、 提交于 2020-12-12 19:44:34
本文3.0版本文章 https://mp.weixin.qq.com/s/3s4_PuuESN-Y8QXZHakHtw 本文是NetCore 2.2的,请不要套用3.0 1、如果看不懂本文,或者比较困难,先别着急问问题,我单写了一个关于依赖注入的小Demo,可以下载看看,多思考思考注入的原理: https://github.com/anjoy8/BlogArti/tree/master/Blog.Core_IOC%26DI 2、重要:如果你实现了解耦,也就是 api 层只引用了 IService 和 IRepository 的话,那每次修改 service 层, 都需要清理解决方案,重新编译项目 ,因为这个时候你的api层的dll,还是之前未修改的代码。 3、重要+ :请注意,依赖注入的目的不是为了解耦,依赖注入是为了 控制反转 ,通俗来说,就是不用我们自己去 new 服务实例 了,所以大家不需要一定去解耦(比如下文说到的 我没有引用 Service层 和 Repository层),我下一个DDD系列,依赖注入就没有解耦,因为我用的是自带的注入,不是Autofac的反射dll ,我解耦的目的,是为了让大家更好的理解,服务是怎么注入到宿主容器里的。   说接上文,上回说到了《 八 || API项目整体搭建 6.3 异步泛型+依赖注入初探 》,后来的标题中,我把仓储两个字给去掉了

Autofac method level interception with Castle DynamicProxy in .NET Core 2

房东的猫 提交于 2020-12-12 05:11:32
问题 I currently wrote an Interceptor which code is below public class TransactionalInterceptor : IInterceptor { public void Intercept(IInvocation invocation) { using (var transaction = ...) { try { invocation.Proceed(); transaction.Commit(); } catch { transaction.Rollback(); } finally { transaction.Dispose(); } } } } but when register this interceptor it will apply to all methods. I have a service class with a repository injected having CRUD methods. I don't want a transaction to be opened for

Autofac method level interception with Castle DynamicProxy in .NET Core 2

只谈情不闲聊 提交于 2020-12-12 05:09:24
问题 I currently wrote an Interceptor which code is below public class TransactionalInterceptor : IInterceptor { public void Intercept(IInvocation invocation) { using (var transaction = ...) { try { invocation.Proceed(); transaction.Commit(); } catch { transaction.Rollback(); } finally { transaction.Dispose(); } } } } but when register this interceptor it will apply to all methods. I have a service class with a repository injected having CRUD methods. I don't want a transaction to be opened for

Inject SignalR IHubContext into service layer with Autofac

霸气de小男生 提交于 2020-12-09 06:34:32
问题 In an app running Framework 4.72, not .NET Core, I'm trying to inject a SignalR IHubContext into a Web API 2.x service. I have my solution broken into three projects, web, service, data. The SignalR hub is in the web layer. I have background code that runs in the service layer and when complete I need it to send a mesage via the hub. This background task is not initiated by the controller. My Global.asax is pretty standard: protected void Application_Start() { GlobalConfiguration.Configure

从壹开始前后端分离【 .NET Core2.0/3.0 +Vue2.0 】框架之十 || AOP面向切面编程浅解析:简单日志记录 + 服务切面缓存

为君一笑 提交于 2020-12-06 04:09:58
本文3.0版本文章 https://mp.weixin.qq.com/s/pjvleNGi_AazZ7COdxQyPQ 代码已上传Github+Gitee,文末有地址   上回《 从壹开始前后端分离【 .NET Core2.0 Api + Vue 2.0 + AOP + 分布式】框架之九 || 依赖注入IoC学习 + AOP界面编程初探 》咱们说到了依赖注入Autofac的使用,不知道大家对IoC的使用是怎样的感觉,我个人表示还是比较可行的,至少不用自己再关心一个个复杂的实例化服务对象了,直接通过接口就满足需求,当然还有其他的一些功能,我还没有说到,抛砖引玉嘛,大家如果有好的想法,欢迎留言,也可以来群里,大家一起学习讨论。昨天在文末咱们说到了AOP面向切面编程的定义和思想,我个人简单使用了下,感觉主要的思路还是通过拦截器来操作,就像是一个中间件一样,今天呢,我给大家说两个小栗子,当然,你也可以合并成一个,也可以自定义扩展,因为我们是真个系列是基于Autofac框架,所以今天主要说的是基于Autofac的Castle动态代理的方法,静态注入的方式以后有时间可以再补充。   时间真快,转眼已经十天过去了,感谢大家的鼓励,批评指正,希望我的文章,对您有一点点儿的帮助,哪怕是有学习新知识的动力也行,至少至少,可以为以后跳槽增加新的谈资 [哭笑],这些天我们从面向对象OOP的开发