public EventServiceTest() { Resolver = IocFactory.CreateRegistry() .AddSingleton <IEventService>(x => new EventService()) .GetResolver(); _fooHost = new FooEventHost(Resolver); _barHost = new BarEventHost(Resolver); }
/// <summary> /// CafeRegistry constructor. /// </summary> internal CafeRegistry() { var mobileService = new Lazy <MobileService>(() => new MobileService(GetResolver())); _serviceRegistry = IocFactory.CreateRegistry() .AddEventService() .AddDictionaryService() .AddSingleton(x => mobileService.Value as IServiceResolver) .AddSingleton(x => mobileService.Value as IPageService) .AddSingleton(x => mobileService.Value as INavigationService) .AddSingleton(x => mobileService.Value as IDeviceService) .AddSingleton(x => mobileService.Value as IAlertService); }
public void ServiceProviderTest() { var resolver = IocFactory.CreateRegistry() .AddSingleton <IDictionaryService>(x => DictionaryService.Current) .AddSingleton <ITestService>(x => new TestService()) .GetResolver(); var propertyService = resolver.Resolve <IDictionaryService>(); Assert.NotNull(propertyService); propertyService.SetEntry("name", "Kilroy"); Assert.Equal("Kilroy", propertyService.GetEntry <string>("name")); var testService = resolver.Resolve <ITestService>(); Assert.Equal("Kilroy is here!", testService.Test()); }
public void IocTestUsingResolutionType() { IDisposableService disposableService; using (var resolver = IocFactory.CreateRegistry() .AddSingleton <ILogger, TestLogWriter>() .AddSingleton <IFooService, FooService>() .AddSingleton <IBarService, BarService>() .AddSingleton <IDisposableService, DisposableService>() .GetResolver()) { //do the actual work here var bar = (IBarService)resolver.Resolve(typeof(IBarService)); bar.DoSomeRealWork(); disposableService = resolver.Resolve <IDisposableService>(); } Assert.True(disposableService.IsDisposed); }
/// <summary> /// Setup the service registry. /// </summary> private void SetupRegistry() { Registry = IocFactory.CreateRegistry(); // .AddLogging(builder => builder.AddConsole().AddDebug()); }
public DictionaryServiceTest() { Resolver = IocFactory.CreateRegistry() .AddSingleton <IDictionaryService>(x => DictionaryService.Current) .GetResolver(); }