public void supply_defaults_with_args() { var container = new Container(x => { x.For<IWidget>().Use<BWidget>(); x.For<IService>().Use<AService>(); }); // SAMPLE: explicit-use-explicit-args var widget = new BWidget(); var service = new BService(); var args = new ExplicitArguments(); args.Set<IWidget>(widget); args.Set<IService>(service); var guyWithWidgetAndService = container .GetInstance<GuyWithWidgetAndService>(args); guyWithWidgetAndService .Widget.ShouldBeTheSameAs(widget); guyWithWidgetAndService .Service.ShouldBeTheSameAs(service); // ENDSAMPLE }
public ITabContentLifetimeHost RestoreTabContent(LayoutStructureTabItem tabItem) { var connectionPropVal = tabItem.ReadProperty(ConnectionIdBackingStorePropertyName); Guid connectionId; ExplicitConnection explicitConnection = null; if (connectionPropVal != null && Guid.TryParse(connectionPropVal, out connectionId)) { explicitConnection = _container.GetInstance <IExplicitConnectionCache>().Get(connectionId).ValueOrDefault(); } var fileIdPropVal = tabItem.ReadProperty(FileIdBackingStorePropertyName); Guid fileId; if (fileIdPropVal == null || !Guid.TryParse(fileIdPropVal, out fileId)) { fileId = Guid.NewGuid(); } var explicitArguments = new ExplicitArguments(); explicitArguments.Set(typeof(Guid), fileId); explicitArguments.Set(typeof(ExplicitConnection), explicitConnection); var tabViewModel = _container.GetInstance <QueryDeveloperViewModel>(explicitArguments); PopulateDocument(tabViewModel); var disposable = Watch(tabViewModel); return(new TabContentLifetimeHost(tabViewModel, closeReason => Cleanup(closeReason, tabViewModel, disposable))); }
public void supply_defaults_with_args() { var container = new Container(x => { x.For <IWidget>().Use <BWidget>(); x.For <IService>().Use <AService>(); }); // SAMPLE: explicit-use-explicit-args var widget = new BWidget(); var service = new BService(); var args = new ExplicitArguments(); args.Set <IWidget>(widget); args.Set <IService>(service); var guyWithWidgetAndService = container .GetInstance <GuyWithWidgetAndService>(args); guyWithWidgetAndService .Widget.ShouldBeTheSameAs(widget); guyWithWidgetAndService .Service.ShouldBeTheSameAs(service); // ENDSAMPLE }
public IVersionControlSystem Get(IStorageRepository profile) { var vcsArgs = new ExplicitArguments(); vcsArgs.Set(profile.GetProfile<ISourceControlConnectionSettingsSource>()); vcsArgs.Set(profile); return ObjectFactory.GetInstance<IVersionControlSystem>(vcsArgs); }
public IVersionControlSystem Get(IStorageRepository profile) { var vcsArgs = new ExplicitArguments(); vcsArgs.Set(profile.GetProfile <ISourceControlConnectionSettingsSource>()); vcsArgs.Set(profile); return(ObjectFactory.GetInstance <IVersionControlSystem>(vcsArgs)); }
private static ServiceHost PerCallServiceHostCreator(Type serviceType, Uri[] baseAddresses) { var args = new ExplicitArguments(); args.Set(serviceType); args.Set(baseAddresses); var serviceHost = ObjectFactory.GetInstance <TelaWebServiceHost>(args); return(serviceHost); }
static ExplicitArguments CreateActivatorArguments(QueryMiddleware <TArgs, TResult> next, object[] args) { var expArgs = new ExplicitArguments(); expArgs.Set(next); foreach (var arg in args) { expArgs.Set(arg.GetType(), arg); } return(expArgs); }
public ITabContentLifetimeHost CreateTabContent() { var explicitArguments = new ExplicitArguments(); explicitArguments.Set(typeof(Guid), Guid.NewGuid()); explicitArguments.Set(typeof(ExplicitConnection), null); var tabViewModel = _container.GetInstance <QueryDeveloperViewModel>(explicitArguments); var disposable = Watch(tabViewModel); return(new TabContentLifetimeHost(tabViewModel, closeReason => Cleanup(closeReason, tabViewModel, disposable))); }
public void RegisterAndFindServicesOnTheExplicitArgument() { var args = new ExplicitArguments(); Assert.IsNull(args.Get <IProvider>()); var red = new RedProvider(); args.Set <IProvider>(red); Assert.AreSame(red, args.Get <IProvider>()); args.Set <IExplicitTarget>(new RedTarget()); Assert.IsInstanceOfType(typeof(RedTarget), args.Get <IExplicitTarget>()); }
public void RegisterAndFindServicesOnTheExplicitArgument() { var args = new ExplicitArguments(); args.Get <IProvider>().ShouldBeNull(); var red = new RedProvider(); args.Set <IProvider>(red); red.ShouldBeTheSameAs(args.Get <IProvider>()); args.Set <IExplicitTarget>(new RedTarget()); args.Get <IExplicitTarget>().ShouldBeOfType <RedTarget>(); }
public static ExplicitArguments ToExplicitArgs(this Dependency[] dependencies) { var arguments = new ExplicitArguments(); dependencies.ToList().ForEach(x => arguments.Set(x.Type, x.Instance)); return(arguments); }
public IVersionControlSystem Get(ISourceControlConnectionSettingsSource settings) { var vcsArgs = new ExplicitArguments(); vcsArgs.Set(settings); return(ObjectFactory.GetInstance <IVersionControlSystem>(vcsArgs)); }
public IPresenter Create(Type presenterType, Type viewType, IView viewInstance) { if (presenterType == null) { throw new ArgumentNullException("presenterType"); } if (viewType == null) { throw new ArgumentNullException("viewType"); } if (viewInstance == null) { throw new ArgumentNullException("viewInstance"); } if (!container.Model.HasImplementationsFor(presenterType)) { lock (registerLock) { if (!container.Model.HasImplementationsFor(presenterType)) { container.Configure(x => x.For(presenterType).HybridHttpOrThreadLocalScoped().Use(presenterType).Named(presenterType.Name)); } } } var args = new ExplicitArguments(); args.Set("view"); args.SetArg("view", viewInstance); return((IPresenter)container.GetInstance(presenterType, args)); }
public IPresenter Create(Type presenterType, Type viewType, IView viewInstance) { if (presenterType == null) throw new ArgumentNullException("presenterType"); if (viewType == null) throw new ArgumentNullException("viewType"); if (viewInstance == null) throw new ArgumentNullException("viewInstance"); if (!container.Model.HasImplementationsFor(presenterType)) { lock (registerLock) { if (!container.Model.HasImplementationsFor(presenterType)) { container.Configure(x => x.For(presenterType).HybridHttpOrThreadLocalScoped().Use(presenterType).Named(presenterType.Name)); } } } var args = new ExplicitArguments(); args.Set("view"); args.SetArg("view", viewInstance); return (IPresenter)container.GetInstance(presenterType, args); }
public static ExplicitArguments ToExplicitArgs(this ServiceArguments arguments) { var explicits = new ExplicitArguments(); arguments.EachService((type, o) => explicits.Set(type, o)); return explicits; }
private ISignalRService <TDto, TRequest> BuildInternal(params object[] parameters) { var args = new ExplicitArguments(); foreach (var @param in parameters) { args.Set(@param.GetType(), @param); } if (!args.Defaults.ContainsKey(typeof(Action <HttpConnectionOptions>))) { args.Defaults.Add(typeof(Action <HttpConnectionOptions>), new Action <HttpConnectionOptions>((_) => { })); } if (!args.Defaults.ContainsKey(typeof(HttpTransportType))) { args.Defaults.Add(typeof(HttpTransportType), HttpTransportType.WebSockets | HttpTransportType.LongPolling | HttpTransportType.ServerSentEvents); } var service = AppCore.Instance.ObjectProvider.GetInstance <ISignalRService <TDto, TRequest> >(args); service.BuildInternal(); return(service); }
private static T GetService <T>(this IDependencyScope scope, params object[] arguments) { var container = scope.GetService <IContainer>(); var explicitArguments = new ExplicitArguments(); arguments.ForEach(x => explicitArguments.Set(x.GetType(), x)); return(container.GetInstance <T>(explicitArguments)); }
public static ISignalRService <TDto, TRequest> GetSignalRService <TDto, TRequest>(this IAppContainer container, TRequest request) where TRequest : IHubRequest <TDto> { var explicitArg = new ExplicitArguments(); explicitArg.Set(request); return(container.ObjectProvider.GetInstance <ISignalRService <TDto, TRequest> >(explicitArg)); }
public static ExplicitArguments ToExplicitArgs(this ServiceArguments arguments) { var explicits = new ExplicitArguments(); arguments.EachService((type, o) => explicits.Set(type, o)); return(explicits); }
public static TPresenter GetPresenter <TPresenter>(object view) //method wil be run each time a new view page is loaded { //to resolve the required presenter and interfaces var explicitArguments = new ExplicitArguments(); //from the IOC container foreach (var implementedInterface in view.GetType().GetInterfaces()) { explicitArguments.Set(implementedInterface, view); } return(Container.GetInstance <TPresenter>(explicitArguments)); }
public override void Execute <T>(ServiceArguments arguments, Action <T> action) { using (var nested = _container.GetNestedContainer()) { var explicits = new ExplicitArguments(); arguments.EachService((type, o) => explicits.Set(type, o)); action(nested.GetInstance <T>(explicits)); } }
public static TPresenter GetPresenter <TPresenter>(object view) { var explicitArguments = new ExplicitArguments(); foreach (var implementedInterface in view.GetType().GetInterfaces()) { explicitArguments.Set(implementedInterface, view); } return(Container.GetInstance <TPresenter>(explicitArguments)); }
private static ExplicitArguments CreateExplicitArguments(params object[] extraParameters) { var args = new ExplicitArguments(); foreach (var parameter in extraParameters) { args.Set(parameter.GetType(), parameter); } return(args); }
public T Build <T>(TypeArguments arguments) { var explicitArguments = new ExplicitArguments(); foreach (var pair in arguments.Defaults) { explicitArguments.Set(pair.Key, pair.Value); } return(Container.GetInstance <T>(explicitArguments)); }
public BuildUpTester() { theDefaultGateway = new DefaultGateway(); var args = new ExplicitArguments(); args.Set<IGateway>(theDefaultGateway); session = BuildSession.Empty(args); theDependencies = new DependencyCollection { { "Age", 34 } }; target = null; }
public void try_get_default_with_explicit_arg() { var foo1 = new Foo(); var args = new ExplicitArguments(); args.Set <IFoo>(foo1); theCache = new SessionCache(theResolver, args); theCache.GetDefault(typeof(IFoo), thePipeline) .ShouldBeTheSameAs(foo1); }
public void SetUp() { TheDefaultGateway = new DefaultGateway(); var args = new ExplicitArguments(); args.Set<IGateway>(TheDefaultGateway); builder = new Plugin(typeof (ClassWithMixOfSetters)).CreateBuilder(); instance = new SmartInstance<ClassWithMixOfSetters>().Ctor<int>("Age").Is(34); _session = BuildSession.Empty(args); _target = null; }
public void get_instance_with_args() { var container = new Container(x => { x.For <FakeLogger>().Use(c => new FakeLogger(c.RootType)); x.For <ILoggerHolder>().Use <WidgetLoggerHolder>(); }); var explicitArguments = new ExplicitArguments(); explicitArguments.Set <IWidget>(new AWidget()); container.GetInstance <ILoggerHolder>(explicitArguments) .Logger.RootType.ShouldEqual(typeof(WidgetLoggerHolder)); }
public void SetUp() { TheDefaultGateway = new DefaultGateway(); var args = new ExplicitArguments(); args.Set <IGateway>(TheDefaultGateway); builder = new Plugin(typeof(ClassWithMixOfSetters)).CreateBuilder(); instance = new SmartInstance <ClassWithMixOfSetters>().Ctor <int>("Age").Is(34); _session = BuildSession.Empty(args); _target = null; }
public IActorProcess AddInternal <TActorProcess>(IActorProcessConfiguration configuration) where TActorProcess : IActorProcess { var args = new ExplicitArguments(); args.Set(configuration); var process = _container.GetInstance <TActorProcess>(args); _actors.AddOrUpdate(configuration.Id.Value, process, (key, @new) => @new); process.Start(); return(process); }
public void SetUp() { TheDefaultGateway = new DefaultGateway(); var args = new ExplicitArguments(); args.Set<IGateway>(TheDefaultGateway); _session = BuildSession.Empty(args); theDependencies = new DependencyCollection {{"Age", 34}}; _target = null; }
public void Configuration(IAppBuilder app) { var container = GlobalConfiguration.Configuration.DependencyResolver.GetService <IContainer>(); var logger = container.GetInstance <ILog>(); logger.Info("Starting Provider Relationships api"); var authenticationStartupArgs = new ExplicitArguments(); authenticationStartupArgs.Set(app); var authenticationStartup = container.GetInstance <IAuthenticationStartup>(authenticationStartupArgs); authenticationStartup.Initialize(); }
public void CanBuildConcreteTypesThatAreNotPreviouslyRegisteredWithArgumentsProvided() { IContainer manager = new Container( registry => registry.For <IProvider>().Use <Provider>()); var differentProvider = new DifferentProvider(); var args = new ExplicitArguments(); args.Set <IProvider>(differentProvider); var classThatUsesProvider = manager.GetInstance <ClassThatUsesProvider>(args); differentProvider.ShouldBeTheSameAs(classThatUsesProvider.Provider); }
public void PassAnArgumentIntoExplicitArgumentsForARequestedInterface() { IContainer manager = new Container( registry => registry.For <IProvider>().Use <LumpProvider>()); var args = new ExplicitArguments(); var theLump = new Lump(); args.Set(theLump); var instance = (LumpProvider)manager.GetInstance <IProvider>(args); theLump.ShouldBeTheSameAs(instance.Lump); }
public void start_with_explicit_args() { var foo1 = new Foo(); var args = new ExplicitArguments(); args.Set <IFoo>(foo1); theCache = new SessionCache(theResolver, args); thePipeline.Stub(x => x.GetDefault(typeof(IFoo))).Throw(new NotImplementedException()); theCache.GetDefault(typeof(IFoo), thePipeline) .ShouldBeTheSameAs(foo1); }
public void CanBuildConcreteTypesThatAreNotPreviouslyRegisteredWithArgumentsProvided() { IContainer manager = new Container( registry => registry.ForRequestedType <IProvider>().TheDefaultIsConcreteType <Provider>()); var differentProvider = new DifferentProvider(); var args = new ExplicitArguments(); args.Set <IProvider>(differentProvider); var classThatUsesProvider = manager.GetInstance <ClassThatUsesProvider>(args); Assert.AreSame(differentProvider, classThatUsesProvider.Provider); }
public void PassAnArgumentIntoExplicitArgumentsForARequestedInterface() { IContainer manager = new Container( registry => registry.ForRequestedType <IProvider>().TheDefaultIsConcreteType <LumpProvider>()); var args = new ExplicitArguments(); var theLump = new Lump(); args.Set(theLump); var instance = (LumpProvider)manager.GetInstance <IProvider>(args); Assert.AreSame(theLump, instance.Lump); }
public void Pass_in_arguments_as_dictionary() { ObjectFactory.Initialize(x => { x.ForRequestedType<IView>().TheDefaultIsConcreteType<View>(); }); var theNode = new Node(); var theTrade = new Trade(); var args = new ExplicitArguments(); args.Set(theNode); args.SetArg("trade", theTrade); var command = ObjectFactory.GetInstance<Command>(args); Assert.IsInstanceOfType(typeof (View), command.View); Assert.AreSame(theNode, command.Node); Assert.AreSame(theTrade, command.Trade); }
public void explicit_wins_over_instance_in_try_get_default() { var foo1 = new Foo(); var args = new ExplicitArguments(); args.Set<IFoo>(foo1); theCache = new SessionCache(theResolverMock, args); var instance = new ConfiguredInstance(typeof(Foo)); instanceGraphMock.GetDefault(typeof(IFoo)).Returns(instance); var foo2 = new Foo(); theResolverMock.ResolveFromLifecycle(typeof(IFoo), instance).Returns(foo2); theCache.GetDefault(typeof(IFoo), thePipeline) .ShouldBeTheSameAs(foo1); }
public void explicit_wins_over_instance_in_try_get_default() { var foo1 = new Foo(); var args = new ExplicitArguments(); args.Set<IFoo>(foo1); theCache = new SessionCache(theResolver, args); var instance = new ConfiguredInstance(typeof (Foo)); theInstances.Stub(x => x.GetDefault(typeof (IFoo))).Return(instance); var foo2 = new Foo(); theResolver.Expect(x => x.ResolveFromLifecycle(typeof (IFoo), instance)).Return(foo2) .Repeat.Once(); theCache.GetDefault(typeof (IFoo), thePipeline) .ShouldBeTheSameAs(foo1); }
public virtual IPresenter Create(Type presenterType, Type viewType, IView viewInstance) { Type abstractViewType = this.GetAbstractViewType(presenterType); if(viewType == null) throw new ArgumentNullException("viewType"); if(!typeof(IView).IsAssignableFrom(viewType)) throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "The view-type \"{0}\" must implement \"{1}\".", viewType.FullName, typeof(IView).FullName), "viewType"); if(viewInstance == null) throw new ArgumentNullException("viewInstance"); ExplicitArguments explicitArguments = new ExplicitArguments(); explicitArguments.Set(abstractViewType, viewInstance); IPresenter presenter = (IPresenter) this._container.GetInstance(presenterType, explicitArguments); if(presenter == null) throw new StructureMapException(202, new object[] {presenterType}); return presenter; }
public void PassExplicitArgsIntoInstanceManager() { var container = new Container(r => { r.ForConcreteType<ExplicitTarget>().Configure .Ctor<IProvider>().Is<RedProvider>() .Ctor<string>("name").Is("Jeremy"); }); var args = new ExplicitArguments(); // Get the ExplicitTarget without setting an explicit arg for IProvider var firstTarget = container.GetInstance<ExplicitTarget>(args); firstTarget.Provider.ShouldBeOfType<RedProvider>(); // Now, set the explicit arg for IProvider args.Set<IProvider>(new BlueProvider()); var secondTarget = container.GetInstance<ExplicitTarget>(args); secondTarget.Provider.ShouldBeOfType<BlueProvider>(); }
public void PassAnArgumentIntoExplicitArgumentsForARequestedInterface() { IContainer manager = new Container( registry => registry.For<IProvider>().Use<LumpProvider>()); var args = new ExplicitArguments(); var theLump = new Lump(); args.Set(theLump); var instance = (LumpProvider) manager.GetInstance<IProvider>(args); Assert.AreSame(theLump, instance.Lump); }
public void PassExplicitArgsIntoInstanceManager() { var container = new Container(r => { r.ForConcreteType<ExplicitTarget>().Configure .CtorDependency<IProvider>().Is<RedProvider>() .WithCtorArg("name").EqualTo("Jeremy"); }); var args = new ExplicitArguments(); // Get the ExplicitTarget without setting an explicit arg for IProvider var firstTarget = container.GetInstance<ExplicitTarget>(args); Assert.IsInstanceOfType(typeof (RedProvider), firstTarget.Provider); // Now, set the explicit arg for IProvider args.Set<IProvider>(new BlueProvider()); var secondTarget = container.GetInstance<ExplicitTarget>(args); Assert.IsInstanceOfType(typeof (BlueProvider), secondTarget.Provider); }
public static void Configure(IContainer container, JsonApiConfiguration jsonApiConfiguration) { container.Configure(cfg => cfg.AddRegistry<JsonApiRegistry>()); var registry = new ResourceTypeRegistry(); foreach (var resourceTypeConfiguration in jsonApiConfiguration.ResourceTypeConfigurations) { var resourceTypeRegistration = resourceTypeConfiguration.BuildResourceTypeRegistration(); registry.AddRegistration(resourceTypeRegistration); var configuration = resourceTypeConfiguration; container.Configure(cfg => { cfg.For<IResourceTypeConfiguration>().Use(configuration).Named(resourceTypeRegistration.Type.FullName).Singleton(); cfg.For<IResourceTypeConfiguration>().Use(configuration).Named(resourceTypeRegistration.ResourceTypeName).Singleton(); }); if (resourceTypeConfiguration.DocumentMaterializerType != null) { container.Configure(cfg => cfg.For(resourceTypeConfiguration.DocumentMaterializerType)); } foreach (var relationship in resourceTypeRegistration.Relationships) { IResourceTypeRelationshipConfiguration relationshipConfiguration; if (resourceTypeConfiguration.RelationshipConfigurations .TryGetValue(relationship.Property.Name, out relationshipConfiguration)) { if (relationshipConfiguration.MaterializerType != null) { container.Configure(cfg => cfg.For(relationshipConfiguration.MaterializerType)); continue; } } // They didn't set an explicit materializer. See if they specified a factory for this resource type. if (configuration.RelatedResourceMaterializerTypeFactory == null) continue; var materializerType = configuration.RelatedResourceMaterializerTypeFactory(relationship); container.Configure(cfg => cfg.For(materializerType)); } } container.Configure(cfg => cfg.For<IResourceTypeRegistry>().Use(c => registry).Singleton()); container.Configure(cfg => { cfg.For<IDocumentMaterializerLocator>() .Use<DocumentMaterializerLocator>() .Ctor<Func<string, IDocumentMaterializer>>().Is(resourceTypeName => { var configuration = container.GetInstance<IResourceTypeConfiguration>(resourceTypeName); var registration = registry.GetRegistrationForResourceTypeName(resourceTypeName); var args = new ExplicitArguments(); args.Set<IResourceTypeRegistration>(registration); if (configuration.DocumentMaterializerType != null) return (IDocumentMaterializer) container.With(args).GetInstance(configuration.DocumentMaterializerType); return container.With(args).GetInstance<IDocumentMaterializer>(); }) .Ctor<Func<Type, IDocumentMaterializer>>().Is(type => { var configuration = container.GetInstance<IResourceTypeConfiguration>(type.FullName); var registration = registry.GetRegistrationForType(type); var args = new ExplicitArguments(); args.Set<IResourceTypeRegistration>(registration); if (configuration.DocumentMaterializerType != null) return (IDocumentMaterializer) container.With(args).GetInstance(configuration.DocumentMaterializerType); return container.With(args).GetInstance<IDocumentMaterializer>(); }) .Ctor<Func<string, string, IRelatedResourceDocumentMaterializer>>().Is((resourceTypeName, relationshipName) => { var configuration = container.GetInstance<IResourceTypeConfiguration>(resourceTypeName); var registration = registry.GetRegistrationForResourceTypeName(resourceTypeName); var relationship = registration.GetFieldByName(relationshipName) as ResourceTypeRelationship; if (relationship == null) throw JsonApiException.CreateForNotFound( string.Format("No relationship `{0}` exists for the resource type `{1}`.", relationshipName, resourceTypeName)); var args = new ExplicitArguments(); args.Set<IResourceTypeRegistration>(registration); args.Set<ResourceTypeRelationship>(relationship); // First, see if they have set an explicit materializer for this relationship IResourceTypeRelationshipConfiguration relationshipConfiguration; if (configuration.RelationshipConfigurations.TryGetValue(relationship.Property.Name, out relationshipConfiguration) && relationshipConfiguration.MaterializerType != null) return (IRelatedResourceDocumentMaterializer)container.With(args).GetInstance(relationshipConfiguration.MaterializerType); // They didn't set an explicit materializer. See if they specified a factory for this resource type. if (configuration.RelatedResourceMaterializerTypeFactory != null) { var materializerType = configuration.RelatedResourceMaterializerTypeFactory(relationship); return (IRelatedResourceDocumentMaterializer)container.With(args).GetInstance(materializerType); } return container.With(args).GetInstance<IRelatedResourceDocumentMaterializer>(); }); }); container.Configure(cfg => cfg.For<ILinkConventions>().Use(c => jsonApiConfiguration.LinkConventions).Singleton()); }
public void try_get_default_with_explicit_arg() { var foo1 = new Foo(); var args = new ExplicitArguments(); args.Set<IFoo>(foo1); theCache = new SessionCache(theResolver, args); theCache.GetDefault(typeof (IFoo), thePipeline) .ShouldBeTheSameAs(foo1); }
public void start_with_explicit_args() { var foo1 = new Foo(); var args = new ExplicitArguments(); args.Set<IFoo>(foo1); theCache = new SessionCache(theResolver, args); thePipeline.Stub(x => x.GetDefault(typeof (IFoo))).Throw(new NotImplementedException()); theCache.GetDefault(typeof (IFoo), thePipeline) .ShouldBeTheSameAs(foo1); }
public void Pass_in_arguments_as_dictionary() { var container = new Container(x => { x.For<IView>().Use<View>(); }); var theNode = new Node(); var theTrade = new Trade(); var args = new ExplicitArguments(); args.Set(theNode); args.SetArg("trade", theTrade); var command = container.GetInstance<Command>(args); command.View.ShouldBeOfType<View>(); theNode.ShouldBeTheSameAs(command.Node); theTrade.ShouldBeTheSameAs(command.Trade); }
public void get_instance_with_args() { var container = new Container(x => { x.For<FakeLogger>().Use(c => new FakeLogger(c.RootType)); x.For<ILoggerHolder>().Use<WidgetLoggerHolder>(); }); var explicitArguments = new ExplicitArguments(); explicitArguments.Set<IWidget>(new AWidget()); container.GetInstance<ILoggerHolder>(explicitArguments) .Logger.RootType.ShouldBe(typeof (WidgetLoggerHolder)); }
public void RegisterAndFindServicesOnTheExplicitArgument() { var args = new ExplicitArguments(); Assert.IsNull(args.Get<IProvider>()); var red = new RedProvider(); args.Set<IProvider>(red); Assert.AreSame(red, args.Get<IProvider>()); args.Set<IExplicitTarget>(new RedTarget()); args.Get<IExplicitTarget>().ShouldBeOfType<RedTarget>(); }
public IVersionControlSystem Get(ISourceControlConnectionSettingsSource settings) { var vcsArgs = new ExplicitArguments(); vcsArgs.Set(settings); return ObjectFactory.GetInstance<IVersionControlSystem>(vcsArgs); }