dryioc

DryIOC and MediatR: Injection using InResolutionScopeOf for both IAsyncNotificationHandler and IAsyncRequestHandler

守給你的承諾、 提交于 2019-12-24 08:12:24
问题 This question is a follow up to my previous question, DryIOC Decorator and InResolutionScopeOf What I'm trying to do is create EF DbContext instances in the resolution scope of both IAsyncRequestHandler and IAsyncNotificationHandler, meaning the context injected in a request can't be the same as one injected in a notification (published from a request). Since the notifications are published from inside the request handlers, this nesting is creating some troubles with my desired setup. It is

DryIOC Container configuration for property injection

∥☆過路亽.° 提交于 2019-12-23 12:36:12
问题 I have search far and wide for a simple example of how to configure a DryIoc container to simply inject dependencies as properties the same way that it injects constructor args. Given the following working example... Container registration: public static void Register(HttpConfiguration config) { var c = new Container().WithWebApi(config); c.Register<IWidgetService, WidgetService>(Reuse.Singleton); c.Register<IWidgetRepository, WidgetRepository>(Reuse.Singleton); } Widget Service: public class

Alternative way to create shell in Prism.Windows 7.1.0?

陌路散爱 提交于 2019-12-13 03:26:29
问题 As of this writing, the upcoming Prism.Windows 7.1.0 from MyGet Package is missing override method CreateShell() and I really wonder if it's gonna be moved into another method or it'll be gone in the final release. If so, what's the alternative solution to implement shell view, assuming the code is from this tutorial and DryIoC container is used instead. 回答1: Rather than using the CreateShell() override, you could create the NavigationService inside of a NavigationView . The code provided in

DryIoc with MediatR: IAsyncRequestHandler Resolve exception

霸气de小男生 提交于 2019-12-12 06:38:36
问题 DryIoc can't seem to Resolve a IAsyncRequestHandler. It throws " An exception of type 'DryIoc.ContainerException' occurred in DryIoc.dll but was not handled in user code Additional information: Unable to resolve MediatR.IRequestHandler. Where no service registrations found and number of Rules.FallbackContainers: 0 and number of Rules.UnknownServiceResolvers: 0 " which is weird because it should be resolving a IAsyncRequestHandler. Another weird thing is that the code runs well on Net.Fiddle

DryIoc, Spring.Net's GetObjectsOfType equivalent?

筅森魡賤 提交于 2019-12-11 07:36:18
问题 With Spring.Net, it's possible to query all objects of a certain (ancestor) type. var ctx = ContextRegistry.GetContext(); var setUsers = ctx.GetObjectsOfType(typeof(ISetUser)).Values.OfType<ISetUser>().ToList(); How can this be done with DryIoc? 回答1: The direct answer given sample classes and interfaces would be: public interface IA { } public interface IB { } public class AB : IA, IB { } public class AA : IA { } [Test] public void Resolve_all_services_implementing_the_interface() { var

DryIOC Decorator and InResolutionScopeOf

喜夏-厌秋 提交于 2019-12-11 06:15:54
问题 I'm trying to setup a dependency which I want to be injected in the resolution scope of a base interface (of MediatR handlers): container.Register<DbContext, Model1>(reuse: Reuse.InResolutionScopeOf(typeof(IAsyncRequestHandler<,>))); However, this interface is being setup with a few decorators, which have a dependency on a IActionHandler which, in turn, depends on the DbContext: public class Decorator<TRequest, TResponse> : IAsyncRequestHandler<TRequest, TResponse> { public Decorator

Registering simple types in a specific example

南楼画角 提交于 2019-12-11 04:29:22
问题 Consider the following ClassA has a constructor that takes an instance of MasterClass and a string and exposes a property called Names of type string[] . ClassB has a constructor that takes an IJuicePresser and a IEnumerable<string> . ClassC has a constructor that takes an IEnumerable<string> . Manually I would do something like this to tie them together. var masterClass = new MasterClass(); var juicePresser = JuicePresser.Create("default"); var classA = new ClassA(masterClass, "string"); var

How to resolve a dependency in IValueConverter in Xamarin.Forms using Prism/DryIoC

和自甴很熟 提交于 2019-12-08 06:26:19
问题 I have a Xamarin.Forms app that uses Prism and DryIoC as the container. I have a value converter where I need to make use of a service I have registered via IContainerRegistry. containerRegistry.RegisterSingleton<IUserService, UserService>(); How do I resolve that dependency without having to resort to constructor injection since IValueConverter gets constructed by XAML and not by DryIoC? Can I use a Service Locator in Prism/DryIoC? And if so, how? Below is the value converter code: public

Resolve one of multiple registrations with DryIoc

不问归期 提交于 2019-12-08 03:58:11
问题 Given the small example below, is there a way to mark (attribute, name convention,... ) the MyInterface argument in MyService2 , so that it will resolve correctly, or is the only way to pass in MyInterface[] ? I know that Castle Windsor can resolve it based on naming convention, but I haven't found something similar in DryIoc public interface MyInterface { } public class MyImplementationA : MyInterface { } public class MyImplementationB : MyInterface { } public class MyService1 { public

DryIOC Event Aggregator

為{幸葍}努か 提交于 2019-12-06 07:59:45
问题 I'm trying to Implement an event aggregator using DryIOC. I have an Event dispatcher as follows: public class DryIocEventDispatcher : IEventDispatcher { private readonly IContainer _container; public DryIocEventDispatcher(IContainer container) { _container = container; } public void Dispatch<TEvent>(TEvent eventToDispatch) where TEvent : EventArgs { foreach (var handler in _container.ResolveMany<IHandles<TEvent>>()) { handler.Handle(eventToDispatch); } } } I have a number of classes that can