autofac

Using Navigation in MasterDetailPage with Autofac and Xamarin.Forms

爷,独闯天下 提交于 2019-12-08 02:36:28
问题 I'm trying to use Autofac in Xamarin.Forms project. I created basic samples successfully, even used ViewFactory for some more complicated samples. However, I'm unable to use MasterDetailPage along with Navigation . I'm using factories and services written by Jonathan Yates. You can find his code here My Application Bootstrapper: protected override void ConfigureApplication(IContainer container) { var viewFactory = container.Resolve<IViewFactory>(); var mainPage = viewFactory.Resolve

How to register an open generic decorator for an open generic registration in Autofac?

时光毁灭记忆、已成空白 提交于 2019-12-08 02:18:18
问题 I have an open generic registration for handlers in autofac that looks like this. builder.RegisterAssemblyTypes(assemblies) .AsClosedTypesOf(typeof (ICommandHandler<>)) .AsImplementedInterfaces(); This works fine and registers all my handlers for there closed types. I now want to register a generic decorator for all of the handlers e.g. a LoggingCommandHandlerDecorator<> In look from autofac documentation that you need to name your implementation so the decorator can be the default

Autofac, ASP.NET MVC 3 httpRequest scope and AutoMapper: No scope with a Tag matching 'httpRequest' is visible

你。 提交于 2019-12-07 21:43:15
问题 When I use a web type registered with autofac from an automapper mapping, I get this error: No scope with a Tag matching 'httpRequest' is visible from the scope in which the instance was requested. This generally indicates that a component registered as per-HTTP request is being reqested by a SingleInstance() component (or a similar scenario.) Under the web integration always request dependencies from the DependencyResolver.Current or ILifetimeScopeProvider.RequestLifetime, never from the

Autofac Dependencies Per Area

江枫思渺然 提交于 2019-12-07 20:16:28
I'm creating a new MVC4 site using Autoface that has a public consumer site as well as an admin area for managing the consumer facing site. The admin site will be located in a different area be using the same services as the consumer facing site, but will not having some of the custom branding features. I've followed the advice given elsewhere of having a ViewDataFactory which provides a set of shared data for the view to use. My goal is to provide a different ViewDataFactory depending on what Area you are in. So for example, here is the Service that implements IViewDataFactory builder

Autofac Resolve Open Generic Interface with Open Generic Class

痞子三分冷 提交于 2019-12-07 17:35:15
问题 So I have an interface and class: public interface IMyInterface<T> where T : ISomeEntity {} public class MyClass<T> : IMyInterface<T> where T : ISomeEntity {} I will have some class that calls for it: public class SomeClass : ISomeClass { public SomeClass (IMyInterface<AuditEntity> myInterface) {} } I've done all sorts of things to get it to register the open generic interface and class with no luck. I just want to say something like: container.RegisterType(typeof(MyClass<>)).As(typeof

XUnit Test Constructor dependence injection with Autofac

…衆ロ難τιáo~ 提交于 2019-12-07 16:11:48
问题 I am implementing Xunit with Autofac, I could make it work by below code: using (var scoped = DbFixture.Container.Resolve<UserReponsitory>()) { var result = (scoped.GetAll()).ToList().Count(); Assert.Equal(2, result); } But I want to inject UserReponsitory to test method instead of using DbFixture.Container.Resolve . Is it possible to make below code work? UnitTest1.cs namespace XUnitTestPro { public class UnitTest1:IClassFixture<DbFixture> { private IUserReponsitory _userReponsitory; public

Configuring AutoMapper to fulfil ITypeConverter<,> constructor dependecies with Autofac

巧了我就是萌 提交于 2019-12-07 16:10:44
问题 My first time working with Autofac to inject AutoMapper's IMapper interface into classes that have an object mapping requirement. I have made some progress, with a little help, getting the various dependencies added to AutoMapper's register using Assembly Scanning: builder.RegisterAssemblyTypes(AppDomain.CurrentDomain.GetAssemblies()) .AsClosedTypesOf(typeof(ITypeConverter<,>)) .AsImplementedInterfaces(); builder.RegisterAssemblyTypes(typeof(AutoMapperExtensions).Assembly) .AssignableTo

Autofac register and resolve with Names

孤者浪人 提交于 2019-12-07 13:49:43
问题 I'm trying to register objects by their names, and later on take them in another type's ctor as parameters, during registration. Hope my example will be clear enough, here it is: public class Obj : IObj { public class Obj(string name) } I register the following objects like this : public void RegisterMyObj(string name) { // Keyed with the object name builder.Register<Obj>().Named<IObj>(name).WithParameter(name).SingleInstance(); } public class ObjectsHolder : IObjectsHolder { public

Azure Cloud Service is dead after Application Pool Recycle

﹥>﹥吖頭↗ 提交于 2019-12-07 13:14:11
问题 I have a deployed Azure Cloud Service WebRole WebAPI with only one instance. I have noticed that if I wait some idle time (No HTTP Requests), Then later on the service is dead, and every request to it results in the following response: { Message: "An error has occurred." } The Azure management dashboard says the instance status is Running. Remote desktop reveals that the Application pool and the web site are both running, and that all the services needed are running. I can't find any relevant

Injecting a specific instance of an interface using Autofac

為{幸葍}努か 提交于 2019-12-07 12:48:18
问题 I have a controller and it receives a specific instance of an interface. The interface looks something like this: public interface IMyInterface { ... implementation goes here } And then I have some classes that implement this interface like this: public class MyClassA : IMyInterface { ... implementation goes here } public class MyClassB : IMyInterface { ... implementation goes here } In my ControllerA I have the following constructor: private ICustomerService customerService; private