autofac

How do I inject a constructor dependency into a ViewModel using Xamarin and Autofac?

本秂侑毒 提交于 2019-12-22 05:26:07
问题 I have a ViewModel and I want to inject another Class into it. I am using Visual Studio with the latest version of Xamarin. I'm using Autofac for registering en resolving dependencies. But I'm new to it and I'm facing a problem which I can't find the solution to, even though it's probably simple. This is the Class in which I want to inject another Class: public IMessagingCenterWrapper MessagingCenterWrapper; public LoginViewModel(IMessagingCenterWrapper messagingCenterWrapper){

Is it possible to inject a list of resolved objects into a constructor using Autofac?

余生颓废 提交于 2019-12-22 01:39:58
问题 I'm new to Autofac (3) and am using it to find a number of classes in several assemblies that implement IRecognizer. So I have: builder.RegisterAssemblyTypes(AppDomain.CurrentDomain.GetAssemblies()).As<IRecognizer>(); which is fine. But I'd like to inject references to the found components into a constructor - sort of: public Detector(List<IRecognizer> recognizers) { this.Recognizers = recognizers; } Is there any way to do this? 回答1: Autofac supports the IEnumerable<T> as a relationship type:

Custom ControllerFactory with autofac

混江龙づ霸主 提交于 2019-12-21 23:26:24
问题 First of all i am a newbie in asp mvc so please be patient. Currently I want to create project where autofac will be IoC container i will reqister custom controller factory. In custom controller factory I want to set implementation Data Repository via constructor of controller. I thought it should be done in that way: ContainerBuilder builder = new ContainerBuilder(); builder.RegisterControllers(asm).InstancePerHttpRequest(); builder.Register(s => new ControllerFactory()).As

How to peek at message while dependencies are being built?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-21 22:41:53
问题 I building multitenancy into the unit of work for a set of services. I want to keep the tenancy question out of the way of day-to-day business domain work, and I do not want to touch every existing consumer in the system (I am retrofitting the multitenancy onto a system without any prior concept of a tenant). Most messages in the system will be contexted by a tenant. However, there will be some infrastructure messages which will not be, particularly for the purpose of automating tenant

Autofac with WebApi & Business Layer

倖福魔咒の 提交于 2019-12-21 20:05:13
问题 I am very new to AutoFac and am trying to use it for my new project with WebApi and Business Layer with contracts and their respective implementations. I have written the IocConfiguration for webapi and invoke from global.asax. However, for my Business Logic how do I setup all my contracts and implementations with autofac? I did go through some tutorials online but however I could not find anything helpful, If someone has a sample app, links that really helps. Edit: AutoMapper profile. public

Understanding how Nop Commerce settings are loaded from the database

拈花ヽ惹草 提交于 2019-12-21 12:55:23
问题 I am working with Nop Commerce and wondering if someone can please help me with my confusion. I have debugged the code many times trying to find out how the settings are loaded on start up of the web application. I just don't get it! All settings classes implement the ISettings interface. Lets take customer settings for example.. I have found out that it is represented by the CustomerSettings class. In the database there is a Setting table . Data for customer settings looks somethng like this

WebApi, Autofac, System.Web.Http.Filters.ActionFilterAttribute Instance Per Request

本秂侑毒 提交于 2019-12-21 09:25:41
问题 We have been using Autofac in our application (MVC 4 now) for a long time, we have dozens of attributes on the base controller everything inherits from and it has all been working fine so when the request begins our service is created and then available through all the attributes and on the controller action. We are now looking at WebApi and have created our WebApi controller and created an attribute on the base controller using the ActionFilterAttribute from the HTTP namespace. However the

autofac registration issue in release v2.4.5.724

喜你入骨 提交于 2019-12-21 07:22:14
问题 I have the following registration builder.Register<Func<Type, IRequestHandler>>( c => request => (IRequestHandler)c.Resolve(request)); Basically I am trying to register a factory method that resolves an instance of IRequestHandler from a given type. This works fine until the version 2.4.3.700. But now I am getting a the following error.. Cannot access a disposed object. Object name: 'This resolve operation has already ended. When registering components using lambdas, the IComponentContext 'c'

How do I make sure that there is one NHibernate ISession per request using Autofac?

邮差的信 提交于 2019-12-21 05:48:28
问题 I have the following code in an Autofac Module that is used in my Application_Start method: builder.Register(c => new Configuration().Configure().BuildSessionFactory()) .SingletonScoped(); builder.Register(c => c.Resolve<ISessionFactory>().OpenSession()) .HttpRequestScoped(); builder.Register<NHibernateSomethingRepository>().As<ISomethingRepository>(); The constructor for the repository takes an ISession as argument. But I end up with one session for the whole application, even though I

Massive controller constructor argument list when using DI in MVC

╄→尐↘猪︶ㄣ 提交于 2019-12-21 05:27:40
问题 I am working on ASP.NET MVC3 solution that uses dependency injection with autofac. Our controllers are being created by autofac and properly and all required objects are being properly passed in. Those objects usually include services, repositories, and mappers converting domain object to MVC (view) models. So the controller constructor looks somewhat like: public abcController( ILogger logger, IabcRepository abcRepository, IabcService abcService, IMapper<AbcDomain, AbcViewModel> abcMapper, .