autofac

Use autofac in multiple project solution

我与影子孤独终老i 提交于 2019-12-21 04:51:40
问题 I have large wpf application. I simplify my problem with autofac. Let say I have ViewModelLocator where I create contrainer. ViewModelLocator is in Company.WPF project, this project refers Company.ViewModels project. var builder = new ContainerBuilder(); builder.RegisterType<MainWindowViewModel>().AsSelf().SingleInstance(); container = builder.Build(); Problem: MainWindowViewModel needs ICompanyService (I use CI) which is in Company.Services project, this project should not be reference from

Injecting external dependencies in Microsoft Bot Framework Dialog using Autofac

混江龙づ霸主 提交于 2019-12-21 04:06:36
问题 I've been trying to pass a service to a LuisDialog from the MessagesController like so: public async Task<HttpResponseMessage> Post([FromBody]Activity activity) ... await Conversation.SendAsync(activity, () => new ActionDialog(botService)); The botService is injected into the MessageController using dependency injection. When I start a bot conversation I get an error: Type 'ThetaBot.Services.BotService' in Assembly 'ThetaBot.Services, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' is

conditional component registration in autofac

霸气de小男生 提交于 2019-12-21 03:45:30
问题 Is it possible to register a component conditionally on an other component's state? Something like: ContainerBuilder.RegisterConditionally<T>( Func<IComponentContext, bool>, Func<IComponentContext, T>); I've found that prior to V2 of autofac one could use a " Register().OnlyIf() " construction that seemed like the one I'm looking for. I would like such feature to conditionally override a default registration. class CommonRegistrations { public virtual void Register(ContainderBuilder builder)

Override autofac registration with plugin

半世苍凉 提交于 2019-12-21 03:32:09
问题 I have an IFoo service implemented by DefaultFoo , and I've registered it as such in my autofac container. Now I would like to allow for an alternative implementation of IFoo to be implemented in a plugin assembly, which can be dropped in a "plugins" folder. How do I configure autofac to prefer this alternative implementation if it is present? 回答1: If you register some interface implementations, Autofac will use the latest registration. Other registrations will be overridden. In your case,

Autofac Lifetimes and the Default Provider within a Matching Lifetime Scope

旧街凉风 提交于 2019-12-21 01:38:33
问题 I have an ASP.NET MVC web application using Autofac for dependency injection. Occasionally, this web application will start a thread to do some work separate from the request thread. When this background thread starts up, it establishes a new Autofac lifetime scope from the root container and runs some action. public IAsyncResult Run<T>(Action<T> action) { var NewTask = System.Threading.Tasks.Task.Factory.StartNew(() => { using (var Scope = Runtime.Container.BeginLifetimeScope()) { var Input

Resolve type without creating object

一曲冷凌霜 提交于 2019-12-21 01:10:10
问题 Here's my problem: I have a container where I register concrete types as interfaces. builder.RegisterType<DeleteOrganization>().As<IDeleteOrganization>(); I'm implementing a SerializationBinder for a serialization project I'm doing and the BindToType method that I need to implement wants me to return a Type object. The BindToType method gives me an assemblyName and typeName (both strings) to help me create a type object. What I want to do is if the typeName is an interface, I want to ask

Autofac and IDisposable interface

强颜欢笑 提交于 2019-12-20 12:02:40
问题 Assuming that I have the following interface and class: public interface IFooRepo : IDisposable { //... } public FooRepo : IFooRepo { //Methods here //Properly implement the IDisposbale.Dispose() here } I use Autofac as IoC container in my application and if I register this as below, can I be sure that it will disposed properly? private static IContainer RegisterServices(ContainerBuilder builder) { builder.RegisterType<FooService>().As<IFooService>(); return builder.Build(); } Or should I

Keyed delegate factories with runtime constructor parameters?

蹲街弑〆低调 提交于 2019-12-20 11:49:53
问题 Lets say I have the following service and components: public interface IService { void DoWork(); } public class ServiceA : IService { private readonly string _name; public ServiceA(string name) { _name = name; } public void DoWork() { //ServiceA DoWork implementation } } public class ServiceB : IService { private readonly string _name; public ServiceB(string name) { _name = name; } public void DoWork() { //ServiceB DoWork implementation } } Notice that each component takes a constructor

JavaScript DI/IoC equivalents to standard DI patterns for statically typed languages

假装没事ソ 提交于 2019-12-20 10:46:58
问题 .NET and Java both have a slew of DI/IoC containers available to them and each have a number of patterns that I've found very useful at various points in working with them. I'm now at a point where I would like to do equivalent things in JavaScript. As JavaScript is a dynamic language, I don't expect DI/IoC containers to have direct equivalents to all the functionality provided by the containers found in statically typed languages so alternatives to these patterns are welcome. I also expect

ASP.net Identity, IoC and sharing DbContext

让人想犯罪 __ 提交于 2019-12-20 10:27:57
问题 Have anyone been successful in attaching an IoC with OWIN ASP.NET Identity to share the same DbContext as the WebApi (or MVC) application? I would like that if ASP.Net identity loads the user, it loads in the same dbcontext as used in the rest of the application. (using AutoFac as IoC - but wouldn't mind an example with other container) Edit : 06/Jan/2014: Just to be a bit more specific, when the ASP.Net identity attempts to use a DbContext it needs to be the same DbContext instance as the