public DependencyInjectionFixture() { _container = new PillarDefaultIoc(); _container.RegisterType <IFoo, Foo>(); _container.RegisterType <IBar, Bar>(); }
public void MissingPrimitiveDefaultValue(IContainerAdapter adapter) { adapter.RegisterType <IService, IndependentService>(); adapter.RegisterType <ServiceWithDependencyAndOptionalInt32Parameter>(); var component = adapter.Resolve <ServiceWithDependencyAndOptionalInt32Parameter>(); Assert.Equal(5, component.Optional); }
public void MissingPrimitiveDefaultValue(IContainerAdapter adapter) { adapter.RegisterType<IService, IndependentService>(); adapter.RegisterType<ServiceWithDependencyAndOptionalInt32Parameter>(); var component = adapter.Resolve<ServiceWithDependencyAndOptionalInt32Parameter>(); Assert.Equal(5, component.Optional); }
public void GracefulRecursionHandling(IContainerAdapter adapter) { this.AssertIsNotCrashingOnRecursion(adapter); adapter.RegisterType <ServiceWithRecursiveDependency1>(); adapter.RegisterType <ServiceWithRecursiveDependency2>(); this.AssertGivesCorrectExceptionWhenResolvingRecursive <ServiceWithRecursiveDependency1>(adapter); }
public void GracefulRecursionHandlingForListDependency(IContainerAdapter adapter) { this.AssertIsNotCrashingOnListRecursion(adapter); adapter.RegisterType <ServiceWithListConstructorDependency <IService[]> >(); adapter.RegisterType <IService, ServiceThatCreatesRecursiveArrayDependency>(); this.AssertGivesCorrectExceptionWhenResolvingRecursive <ServiceWithListConstructorDependency <IService[]> >(adapter); }
public void MissingPrimitive(IContainerAdapter adapter) { adapter.RegisterType <IService, IndependentService>(); adapter.RegisterType <ServiceWithDependencyAndOptionalInt32Parameter>(); var component = adapter.Resolve <ServiceWithDependencyAndOptionalInt32Parameter>(); Assert.NotNull(component); }
public void MissingPrimitive(IContainerAdapter adapter) { adapter.RegisterType<IService, IndependentService>(); adapter.RegisterType<ServiceWithDependencyAndOptionalInt32Parameter>(); var component = adapter.Resolve<ServiceWithDependencyAndOptionalInt32Parameter>(); Assert.NotNull(component); }
public void BasicLazySupport(IContainerAdapter adapter) { adapter.RegisterType<IService, IndependentService>(); adapter.RegisterType<ServiceWithSimpleConstructorDependency>(); var lazy = adapter.Resolve<Lazy<ServiceWithSimpleConstructorDependency>>(); Assert.NotNull(lazy); Assert.NotNull(lazy.Value); }
public void NotCreatingLazyPrematurely(IContainerAdapter adapter) { adapter.RegisterType<IService, IndependentService>(); adapter.RegisterType<ServiceWithSimpleConstructorDependency>(); var lazy = adapter.Resolve<Lazy<ServiceWithSimpleConstructorDependency>>(); Assert.NotNull(lazy); Assert.False(lazy.IsValueCreated); }
public void ConstructorDependency(IContainerAdapter adapter) { adapter.RegisterType <IService, IndependentService>(); adapter.RegisterType <ServiceWithSimpleConstructorDependency>(); var component = adapter.Resolve <ServiceWithSimpleConstructorDependency>(); Assert.NotNull(component.Service); Assert.IsAssignableFrom <IndependentService>(component.Service); }
public void ConstructorDependency(IContainerAdapter adapter) { adapter.RegisterType<IService, IndependentService>(); adapter.RegisterType<ServiceWithSimpleConstructorDependency>(); var component = adapter.Resolve<ServiceWithSimpleConstructorDependency>(); Assert.NotNull(component.Service); Assert.IsAssignableFrom<IndependentService>(component.Service); }
public void RegistrationAtAnyStage(IContainerAdapter adapter) { adapter.RegisterType <IService, IndependentService>(); adapter.Resolve <IService>(); adapter.RegisterType <IService2, IndependentService2>(); var resolved = adapter.Resolve <IService2>(); Assert.NotNull(resolved); }
public void BasicLazySupport(IContainerAdapter adapter) { adapter.RegisterType <IService, IndependentService>(); adapter.RegisterType <ServiceWithSimpleConstructorDependency>(); var lazy = adapter.Resolve <Lazy <ServiceWithSimpleConstructorDependency> >(); Assert.NotNull(lazy); Assert.NotNull(lazy.Value); }
public void NotCreatingLazyPrematurely(IContainerAdapter adapter) { adapter.RegisterType <IService, IndependentService>(); adapter.RegisterType <ServiceWithSimpleConstructorDependency>(); var lazy = adapter.Resolve <Lazy <ServiceWithSimpleConstructorDependency> >(); Assert.NotNull(lazy); Assert.False(lazy.IsValueCreated); }
public void FactoryWithNoParameters(IContainerAdapter adapter) { adapter.RegisterType<IService, IndependentService>(); adapter.RegisterType<ServiceWithSimpleConstructorDependency>(); var func = adapter.Resolve<Func<ServiceWithSimpleConstructorDependency>>(); Assert.NotNull(func); var result = func(); Assert.NotNull(result); }
public void FactoryWithNoParameters(IContainerAdapter adapter) { adapter.RegisterType <IService, IndependentService>(); adapter.RegisterType <ServiceWithSimpleConstructorDependency>(); var func = adapter.Resolve <Func <ServiceWithSimpleConstructorDependency> >(); Assert.NotNull(func); var result = func(); Assert.NotNull(result); }
public void FactoryWithParameter(IContainerAdapter adapter) { adapter.RegisterType<IService, IndependentService>(); adapter.RegisterType<ServiceWithTwoConstructorDependencies>(); var service2 = new IndependentService2(); var func = adapter.Resolve<Func<IService2, ServiceWithTwoConstructorDependencies>>(); Assert.NotNull(func); var result = func(service2); Assert.NotNull(result); Assert.Same(service2, result.Service2); }
public void AssertResolvesListDependencyFor <TTestComponent>(IContainerAdapter adapter) where TTestComponent : IServiceWithListDependency <IEnumerable <IService> > { adapter.RegisterType <IService, IndependentService>(); adapter.RegisterType <TTestComponent>(); var resolved = adapter.Resolve <TTestComponent>(); Assert.NotNull(resolved); Assert.NotNull(resolved.Services); Assert.Equal(1, resolved.Services.Count()); Assert.IsAssignableFrom <IndependentService>(resolved.Services.First()); }
public void ReasonableConstructorSelection(IContainerAdapter adapter) { adapter.RegisterType <IService, IndependentService>(); adapter.RegisterType <ServiceWithMultipleConstructors>(); var resolved = adapter.Resolve <ServiceWithMultipleConstructors>(); Assert.NotNull(resolved); Assert.Equal( ServiceWithMultipleConstructors.ConstructorNames.MostResolvable, resolved.UsedConstructorName ); }
public void FactoryWithParameterForSubdependency(IContainerAdapter adapter) { adapter.RegisterType<ServiceWithSimpleConstructorDependency>(); adapter.RegisterType<ServiceWithDependencyOnServiceWithOtherDependency>(); var service = new IndependentService(); var func = adapter.Resolve<Func<IService, ServiceWithDependencyOnServiceWithOtherDependency>>(); Assert.NotNull(func); var result = func(service); Assert.NotNull(result); Assert.Same(service, result.Service.Service); }
public void FactoryWithParameterForSubdependency(IContainerAdapter adapter) { adapter.RegisterType <ServiceWithSimpleConstructorDependency>(); adapter.RegisterType <ServiceWithDependencyOnServiceWithOtherDependency>(); var service = new IndependentService(); var func = adapter.Resolve <Func <IService, ServiceWithDependencyOnServiceWithOtherDependency> >(); Assert.NotNull(func); var result = func(service); Assert.NotNull(result); Assert.Same(service, result.Service.Service); }
public void FactoryWithParameter(IContainerAdapter adapter) { adapter.RegisterType <IService, IndependentService>(); adapter.RegisterType <ServiceWithTwoConstructorDependencies>(); var service2 = new IndependentService2(); var func = adapter.Resolve <Func <IService2, ServiceWithTwoConstructorDependencies> >(); Assert.NotNull(func); var result = func(service2); Assert.NotNull(result); Assert.Same(service2, result.Service2); }
public void PropertyDependencyIsOptional(IContainerAdapter adapter) { adapter.RegisterType<ServiceWithSimplePropertyDependency>(); var component = adapter.Resolve<ServiceWithSimplePropertyDependency>(); Assert.Null(component.Service); }
public void PropertyDependencyIsOptional(IContainerAdapter adapter) { adapter.RegisterType <ServiceWithSimplePropertyDependency>(); var component = adapter.Resolve <ServiceWithSimplePropertyDependency>(); Assert.Null(component.Service); }
public void IndependentServiceRegisteredAsSelf(IContainerAdapter adapter) { adapter.RegisterType<IndependentService>(); var component = adapter.Resolve<IndependentService>(); Assert.NotNull(component); }
public void IndependentServiceRegisteredAsSelf(IContainerAdapter adapter) { adapter.RegisterType <IndependentService>(); var component = adapter.Resolve <IndependentService>(); Assert.NotNull(component); }
public static IContainerAdapter RegisterInstanceType <TFrom, TTo>(this IContainerAdapter adapter) where TTo : TFrom { { Lokad.Enforce.Argument(() => adapter); } return(adapter.RegisterType <TFrom, TTo>(ContainerRegistrationScope.Instance)); }
public void ConstructorDependencyUsingInstance(IContainerAdapter adapter) { var instance = new IndependentService(); adapter.RegisterInstance<IService>(instance); adapter.RegisterType<ServiceWithSimpleConstructorDependency>(); var dependent = adapter.Resolve<ServiceWithSimpleConstructorDependency>(); Assert.Same(instance, dependent.Service); }
public void RegisterTypeFactory() { _container = new PillarDefaultIoc(); _container.RegisterType <IFoo>(() => new Foo()); var foo1 = _container.Resolve <IFoo>(); var foo2 = _container.Resolve <IFoo>(); Assert.NotSame(foo1, foo2); }
public void ConstructorDependencyUsingInstance(IContainerAdapter adapter) { var instance = new IndependentService(); adapter.RegisterInstance <IService>(instance); adapter.RegisterType <ServiceWithSimpleConstructorDependency>(); var dependent = adapter.Resolve <ServiceWithSimpleConstructorDependency>(); Assert.Same(instance, dependent.Service); }
internal static void RegisterPillarDependencies(this IContainerAdapter container) { // service registration container.RegisterSingleton(container); // the container itself can be injected container.RegisterSingleton <IDialogProvider, DialogService>(); container.RegisterSingleton <IViewFactory, ViewFactory>(); container.RegisterSingleton <INavigator, Navigator>(); container.RegisterSingleton <IMessenger, Messenger>(); // current page resolver container.RegisterType <Func <Page> >(() => GetCurrentPage); // current PageProxy container.RegisterSingleton <IPage, PageProxy>(); }
protected override void RegisterDependencies(IContainerAdapter container) { container.RegisterSingleton <LoginViewModel>(); container.RegisterSingleton <LoginView>(); container.RegisterSingleton <HomeViewModel>(); container.RegisterSingleton <HomeView>(); container.RegisterType <EventToCommandViewModel>(); container.RegisterType <EventToCommandView>(); container.RegisterType <DialogViewModel>(); container.RegisterType <DialogView>(); container.RegisterType <TemplateSelectorViewModel>(); container.RegisterType <TemplateSelectorView>(); container.RegisterType <MessengerViewModel>(); container.RegisterType <MessengerView>(); }
// transient generics public static void RegisterType <TFrom, TTo>(this IContainerAdapter adapter) where TFrom : class where TTo : class, TFrom { adapter.RegisterType(typeof(TFrom), typeof(TTo)); }
public static void RegisterType <TInterface>(this IContainerAdapter adapter, Func <TInterface> implementationFactory) where TInterface : class { adapter.RegisterType(typeof(TInterface), implementationFactory); }
protected override void RegisterDependencies(IContainerAdapter container) { container.RegisterType <MockViewModel>(); container.RegisterType <MockView>(); }
public virtual void Load(IContainerAdapter adapter) { adapter.RegisterType(typeof(PluginBase), this.GetType()); }
public static void RegisterType <TInterface>(this IContainerAdapter adapter) where TInterface : class { adapter.RegisterType(typeof(TInterface), typeof(TInterface)); }
public void CannotRegisterDependencyAfterResolve() { _container.Resolve <IFoo>(); Assert.Throws <InvalidOperationException>(() => _container.RegisterType <ContentPage>()); }