public UnboundGeneric(Type serviceType, Type type, IRegistrationContext parentContext, RegistrationFactory registrationFactory) { this.serviceType = serviceType; this.Type = type; this.parentContext = parentContext; this.RegistrationFactory = registrationFactory; }
public IAsWeakBinding WithRegistrationFactory(RegistrationFactory registrationFactory) { if (registrationFactory == null) throw new ArgumentNullException("registrationFactory"); this.RegistrationFactory = registrationFactory; return this; }
public ServiceLocator(IContainerConfiguration containerConfiguration) { var assembliesProvider = new AssembliesProvider(containerConfiguration); var compositionRootProvider = new CompositionRootProvider(assembliesProvider); var registry = new Registry(); var typesProvider = new TypesProvider(); var objectInstantiatingGenerator = new ObjectInstantiatingGenerator(); var intantiationProvidingGeneratingStrategy = new InstantiationProvidingGeneratingStrategy(objectInstantiatingGenerator); var scopeKeeper = new ScopeKeeper(); var perRequestProvidingGeneratingStrategy = new PerRequestProvidingGeneratingStrategy(scopeKeeper, objectInstantiatingGenerator); var perContainerProvidingGeneratingStrategy = new PerContainerProvidingGeneratingStrategy(scopeKeeper, objectInstantiatingGenerator); var arrayInstantiatingGenerator = new ArrayInstantiatingGenerator(); var enumerableProvidingGeneratingStrategy = new EnumerableProvidingGeneratingStrategy(arrayInstantiatingGenerator); var generatingStrategyProvider = new GeneratingStrategyProvider(intantiationProvidingGeneratingStrategy, perRequestProvidingGeneratingStrategy, perContainerProvidingGeneratingStrategy, enumerableProvidingGeneratingStrategy); var objectGraphProvider = new ObjectGraphProvider(registry, generatingStrategyProvider); var instanceProvidingMethodBodyGenerator = new InstanceProvidingMethodBodyGenerator(); var instanceProvidingMethodGenerator = new InstanceProvidingMethodGenerator(objectGraphProvider, instanceProvidingMethodBodyGenerator); var registrationFactory = new RegistrationFactory(typesProvider, instanceProvidingMethodGenerator); var assemblyBoundedRegistrator = new AssemblyBoundedRegistrator(registry, registrationFactory); var registratorProvider = new RegistratorProvider(assemblyBoundedRegistrator); var dependenciesCompositor = new DependenciesCompositor(compositionRootProvider, registratorProvider); var registrySaturator = new RegistrySaturator(registry, scopeKeeper); var registryInitializer = new RegistryInitializer(dependenciesCompositor, registrySaturator); _map.Add(typeof(IRegistryInitializer), registryInitializer); _map.Add(typeof(IScopeKeeper), scopeKeeper); var resolver = new Resolver(registry, scopeKeeper); _map.Add(typeof(IResolver), resolver); }
public void TestWithParametersCalledTwice() { RegistrationFactory registrationFactory = new RegistrationFactory(new Mock <IIocContainer>().Object); Assert.Throws <InvalidRegistrationException>(() => registrationFactory.Register <IFoo, Foo>(Lifestyle.Transient).WithParameters(new Bar()).WithParameters(new Test())); Assert.Throws <InvalidRegistrationException>(() => registrationFactory.Register <IFoo, Foo>(Lifestyle.Transient).WithParameters((0, new Bar())).WithParameters((1, new Test()))); }
public UnboundGeneric(Type serviceType, Type type, IRegistrationContext parentContext, RegistrationFactory registrationFactory) { this.serviceType = serviceType; this.Type = type; this.parentContext = parentContext; this.RegistrationFactory = registrationFactory; }
private void RegisterSubgroup(Action <IRegister> action, FilterInfo parentInfo) { var andInfo = new FilterInfo(store.NextId, parentInfo.DiagInfo, parentInfo.FilterToken, parentInfo.Priority); var andGroup = new FilterRegistration(() => new AndGroup(null, andInfo)); store.RegisterFilter(andGroup); action(RegistrationFactory.GetRegistration(store, andInfo.FilterToken, priority)); }
public void RelationNameShouldBeUsed() { var relation = "some-relation"; var registration = RegistrationFactory.Create <Person>(relation, false, false); var result = _handler.Process(registration, _linkBuilder, _object); result.Relation.Should().Be(relation); }
public InsuranceNeusoft(string centerName) { TransactionFactory transactionFactory = new TransactionFactory(); RegistrationFactory registrationFactory = new RegistrationFactory(); transaction = transactionFactory.CreateTransaction(centerName); registration = registrationFactory.CreateRegistration(centerName); center = centerName; }
protected override void RegisterTriggerActions(RegistrationFactory register) { register.OnTrigger(Trigger.UpdateTime) .Do((request, token) => { CurrentData.Now = ServiceClock.CurrentTime(); return(Task.CompletedTask); }); }
public IFilterToken And(IDiagInfo diagInfo, Action <IRegister> action) { var info = new FilterInfo(store.NextId, diagInfo, groupToken, priority); var andGroup = new FilterRegistration(() => new AndGroup(dependencies, info)); store.RegisterFilter(andGroup); action(RegistrationFactory.GetRegistration(store, info.FilterToken, priority)); return(info.FilterToken); }
public IAsWeakBinding WithRegistrationFactory(RegistrationFactory registrationFactory) { if (registrationFactory == null) { throw new ArgumentNullException("registrationFactory"); } this.RegistrationFactory = registrationFactory; return(this); }
public void TestOnCreate() { RegistrationFactory registrationFactory = new RegistrationFactory(new Mock <IIocContainer>().Object); ITypedRegistrationBase <ITest, Test> testRegistration = registrationFactory.Register <ITest, Test>(Lifestyle.Transient).OnCreate(t => t.DoSomething()); Test test = new Test(); Assert.Throws <Exception>(() => testRegistration.OnCreateAction(test)); }
protected override void ConfigureContainer() { ReflectionUtils.ForceLoadAssembliesBySchema("VirtualFightStick.*.dll"); base.ConfigureContainer(); //UnityConfiguration.ConfigureContainer(Container); RegistrationFactory.BootstrapApplication(Container); }
public void TestWithParameters() { RegistrationFactory registrationFactory = new RegistrationFactory(new Mock <IIocContainer>().Object); IBar bar = new Bar(); ITest test = new Test(); IRegistrationBase <IFoo> testRegistration = registrationFactory.Register <IFoo, Foo>(Lifestyle.Transient).WithParameters(bar, test); Assert.AreEqual(bar, testRegistration.Parameters[0]); Assert.AreEqual(test, testRegistration.Parameters[1]); }
public void TestWithParametersDifferentOrder() { RegistrationFactory registrationFactory = new RegistrationFactory(new Mock <IIocContainer>().Object); IBar bar = new Bar(); ITest test = new Test(); IRegistrationBase <IFoo> testRegistration = registrationFactory.Register <IFoo, Foo>(Lifestyle.Transient).WithParameters((0, bar), (3, test), (2, "SomeString")); Assert.AreEqual(bar, testRegistration.Parameters[0]); Assert.IsInstanceOf <InternalResolvePlaceholder>(testRegistration.Parameters[1]); Assert.AreEqual("SomeString", testRegistration.Parameters[2]); Assert.AreEqual(test, testRegistration.Parameters[3]); }
public void AddRegistration(RegistrationFactory registration) { CatalogRegistration current; if(_types.TryGetValue(registration.RegistrationType, out current)) { if (current.IsExisting) throw new ServiceBookException("An existing registration already exists for " + registration.RegistrationType.GetTypeName()); if (current.IsExplicit) throw new ServiceBookException("An explicit registration already exists for " + registration.RegistrationType.GetTypeName()); current.Registration = registration; return; } _types.AddValue(new CatalogRegistration {Registration = registration, IsExplicit = true}); }
public ClientContext() { RegistrationFactory = A.Fake <SignalR.Client.Registration.IFactory>(); A.CallTo(() => RegistrationFactory.For(A <IIdentity> .Ignored, A <IEntity> .Ignored, A <IObserver <IMessage> > .Ignored)) .ReturnsLazily( call => { IIdentity identity = call.GetArgument <IIdentity>(0); IEntity entity = call.GetArgument <IEntity>(1); IObserver <IMessage> observer = call.GetArgument <IObserver <IMessage> >(2); return(new SignalR.Client.Registration.Instance(identity.AsDto(), entity.AsDto(), observer)); } ); Kernel = new Ninject.StandardKernel(); Kernel.Load(new[] { new SignalR.Client.Module() }); Kernel.Bind <SignalR.Client.Registration.IFactory>().ToConstant(RegistrationFactory).InSingletonScope(); }
protected override void RegisterTriggerActions(RegistrationFactory register) { register.OnTrigger(Trigger.Open) .WhenInState(State.Pending) .Do((req, ct) => { var data = As <AccountRequest.OpenData>(req); CurrentData.Name = data.Name; CurrentData.OpenDate = ServiceClock.CurrentTime(); CurrentData.Ssn = data.Ssn; CurrentData.InitialBalance = req.Open.InitialBalance.GetValueOrDefault(0); return(Task.CompletedTask); }); register.OnTrigger(Trigger.Update) .Do(async(req, ct) => { await Task.CompletedTask; var data = As <AccountRequest.UpdateData>(req); CurrentData.Name = data.Name; SetErrorCode(100, ErrorAction.AllowTrigger); }); }
public void NullStringRelationNameCantBeProcessed() { var registration = RegistrationFactory.Create <Person>(null, false, false); _handler.CanProcess(registration, _linkBuilder).Should().BeFalse(); }
public void AddRegistrationFactory(RegistrationFactory registrationFactory) { _types[registrationFactory.RegistrationType].Add(registrationFactory); }
static void Main(string[] args) { int n = 1000000; // 1 mln double[] times = new double[5]; TimeSpan roznica; DateTime startTime, stopTime; var simpleFactory = SimpleFactory.Instance; Ships ship; startTime = DateTime.Now; for (int i = 0; i < n; i++) { ship = simpleFactory.CreateFrigate("cobalt"); } stopTime = DateTime.Now; roznica = stopTime - startTime; times[0] = roznica.TotalMilliseconds; //------------------------------------------------------------------------------ startTime = DateTime.Now; MethodFactory methodFactory = EarthFactory.Instance; for (int i = 0; i < n; i++) { ship = methodFactory.BuildFrigate("cobalt") as Ships; } stopTime = DateTime.Now; roznica = stopTime - startTime; times[1] = roznica.TotalMilliseconds; //------------------------------------------------------------------------------ AbstractFactory abstractFactory = new Abstract1(EarthAbstractFactory.Instance); startTime = DateTime.Now; for (int i = 0; i < n; i++) { ship = abstractFactory.CreateFrigate() as Ships; } stopTime = DateTime.Now; roznica = stopTime - startTime; times[2] = roznica.TotalMilliseconds; //------------------------------------------------------------------------------ RegistrationFactory registrationFactory = RegistrationFactory.Instance; registrationFactory.BuildShip("cobalt", typeof(Frigate)); startTime = DateTime.Now; for (int i = 0; i < n; i++) { ship = abstractFactory.CreateFrigate() as Ships; } stopTime = DateTime.Now; roznica = stopTime - startTime; times[3] = roznica.TotalMilliseconds; //------------------------------------------------------------------------------ RegistrationFactoryWithReflection reflectionFactory = RegistrationFactoryWithReflection.Instance; reflectionFactory.BuildShip(); startTime = DateTime.Now; for (int i = 0; i < n; i++) { ship = abstractFactory.CreateFrigate() as Ships; } stopTime = DateTime.Now; roznica = stopTime - startTime; times[4] = roznica.TotalMilliseconds; Console.WriteLine("Porównanie czasu tworzenia obiektów przez fabryki:"); Console.WriteLine("Simple Factory: " + times[0] + " ms"); Console.WriteLine("Factory Method: " + times[1] + " ms"); Console.WriteLine("Abstract Factory: " + times[2] + " ms"); Console.WriteLine("\nZ rejertracją klas:"); Console.WriteLine("NoReflection: " + times[3] + " ms"); Console.WriteLine("Reflection: " + times[4] + " ms"); Console.ReadKey(); }
public void TestWithParametersNoParametersGiven() { RegistrationFactory registrationFactory = new RegistrationFactory(new Mock <IIocContainer>().Object); Assert.Throws <InvalidRegistrationException>(() => registrationFactory.Register <IFoo, Foo>(Lifestyle.Transient).WithParameters((object[])null)); Assert.Throws <InvalidRegistrationException>(() => registrationFactory.Register <IFoo, Foo>(Lifestyle.Transient).WithParameters(((int index, object parameter)[])null));
protected virtual void RegisterTriggerActions(RegistrationFactory register) { }
public IRegister Priority(int priority) => RegistrationFactory.GetRegistration(store, null, priority);