internal object GetWithDescriptor(BuiltServiceDescriptor descriptor, IContainerScope scope)
        {
            if (descriptor.IsPool)
            {
                return(GetFromPool(descriptor, scope));
            }

            if (descriptor.Implementation == ImplementationType.Scoped && scope == null)
            {
                throw new ScopeException($"{descriptor.ServiceType.ToTypeString()} is registered as scoped service but trying to create instance when scope is null");
            }

            object service;

            if (scope != null && descriptor.Implementation == ImplementationType.Scoped)
            {
                service = scope.Get(descriptor.ServiceType);
            }
            else
            {
                service = descriptor.CreateInstance(this, scope);
            }

            return(ApplyAfterGet(descriptor, service));
        }
示例#2
0
        public void Transient()
        {
            ServiceContainer services = new ServiceContainer();

            services.AddTransientPool <ISingleService, SingleService>();

            IContainerScope scope = services.CreateScope();

            ISingleService single = services.Get <ISingleService>(scope);

            single.Foo = "single";

            ISingleService s1 = services.Get <ISingleService>(scope);

            Assert.NotEqual(single.Foo, s1.Foo);

            ISingleService s2 = services.Get <ISingleService>();

            Assert.NotEqual(single.Foo, s2.Foo);

            IContainerScope scope2 = services.CreateScope();
            ISingleService  s3     = services.Get <ISingleService>(scope2);

            Assert.NotEqual(single.Foo, s3.Foo);
        }
示例#3
0
        public void TransientInTransientPool()
        {
            ServiceContainer services = new ServiceContainer();

            services.AddTransientPool <IParentService, ParentService>();
            services.AddTransient <IFirstChildService, FirstChildService>();
            services.AddTransient <ISecondChildService, SecondChildService>();

            IContainerScope scope  = services.CreateScope();
            IParentService  parent = services.Get <IParentService>(scope);

            parent.Foo        = "parent";
            parent.First.Foo  = "first";
            parent.Second.Foo = "second";

            IParentService p = services.Get <IParentService>(scope);

            Assert.NotEqual(parent.Foo, p.Foo);
            Assert.NotEqual(parent.First.Foo, p.First.Foo);
            Assert.NotEqual(parent.Second.Foo, p.Second.Foo);

            IFirstChildService f1 = services.Get <IFirstChildService>();
            IFirstChildService f2 = services.Get <IFirstChildService>(scope);

            Assert.NotEqual(parent.First.Foo, f1.Foo);
            Assert.NotEqual(parent.First.Foo, f2.Foo);

            ISecondChildService s1 = services.Get <ISecondChildService>();
            ISecondChildService s2 = services.Get <ISecondChildService>(scope);

            Assert.NotEqual(parent.Second.Foo, s1.Foo);
            Assert.NotEqual(parent.Second.Foo, s2.Foo);
        }
示例#4
0
        public SagaExecutor(IHandlerTypeInvoker handlerInvoker, IContainerScope container)
        {
            HandlerInvoker = handlerInvoker;

            Container = container;
            ExtractSagaType();
        }
示例#5
0
        public void ScopedInTransient()
        {
            ServiceContainer services = new ServiceContainer();

            services.AddTransient <IParentService, ParentService>();
            services.AddScoped <IFirstChildService, FirstChildService>();
            services.AddScoped <ISecondChildService, SecondChildService>();

            Assert.Throws <ScopeException>(() => services.Get <IParentService>());
            Assert.Throws <ScopeException>(() => services.Get <IFirstChildService>());
            Assert.Throws <ScopeException>(() => services.Get <ISecondChildService>());

            IContainerScope scope  = services.CreateScope();
            IParentService  parent = services.Get <IParentService>(scope);

            parent.Foo        = "parent";
            parent.First.Foo  = "first";
            parent.Second.Foo = "second";

            IParentService p1 = services.Get <IParentService>(scope);

            Assert.NotEqual(parent.Foo, p1.Foo);
            Assert.Equal(parent.First.Foo, p1.First.Foo);
            Assert.Equal(parent.Second.Foo, p1.Second.Foo);

            IContainerScope scope2 = services.CreateScope();
            IParentService  p2     = services.Get <IParentService>(scope2);

            Assert.NotEqual(parent.Foo, p2.Foo);
            Assert.NotEqual(parent.First.Foo, p2.First.Foo);
            Assert.NotEqual(parent.Second.Foo, p2.Second.Foo);
        }
示例#6
0
        public void TransientInScoped()
        {
            ServiceContainer services = new ServiceContainer();

            services.AddScoped <IParentService, ParentService>();
            services.AddTransient <IFirstChildService, FirstChildService>();
            services.AddTransient <ISecondChildService, SecondChildService>();

            IContainerScope scope  = services.CreateScope();
            IParentService  parent = services.Get <IParentService>(scope);

            parent.Foo        = "parent";
            parent.First.Foo  = "first";
            parent.Second.Foo = "second";

            //services in scoped service is created only once (cuz they created via parent)
            IParentService p = services.Get <IParentService>(scope);

            Assert.Equal(parent.Foo, p.Foo);
            Assert.Equal(parent.First.Foo, p.First.Foo);
            Assert.Equal(parent.Second.Foo, p.Second.Foo);

            IFirstChildService first = services.Get <IFirstChildService>(scope);

            Assert.NotEqual(parent.First.Foo, first.Foo);

            ISecondChildService second = services.Get <ISecondChildService>(scope);

            Assert.NotEqual(parent.Second.Foo, second.Foo);
        }
示例#7
0
        public async Task ScopedInTransientPool()
        {
            ServiceContainer services = new ServiceContainer();

            services.AddTransientPool <IParentService, ParentService>();
            services.AddScoped <IFirstChildService, FirstChildService>();
            services.AddScoped <ISecondChildService, SecondChildService>();

            IContainerScope scope  = services.CreateScope();
            IParentService  parent = await services.Get <IParentService>(scope);

            parent.Foo        = "parent";
            parent.First.Foo  = "first";
            parent.Second.Foo = "second";

            IParentService p = await services.Get <IParentService>(scope);

            Assert.NotEqual(parent.Foo, p.Foo);
            Assert.Equal(parent.First.Foo, p.First.Foo);
            Assert.Equal(parent.Second.Foo, p.Second.Foo);

            await Assert.ThrowsAsync <InvalidOperationException>(async() => await services.Get <IFirstChildService>());

            IFirstChildService f2 = await services.Get <IFirstChildService>(scope);

            Assert.Equal(parent.First.Foo, f2.Foo);

            await Assert.ThrowsAsync <InvalidOperationException>(async() => await services.Get <ISecondChildService>());

            ISecondChildService s2 = await services.Get <ISecondChildService>(scope);

            Assert.Equal(parent.Second.Foo, s2.Foo);
        }
示例#8
0
        public SagaExecutor(IHandlerTypeInvoker handlerInvoker, IContainerScope container)
        {
            HandlerInvoker = handlerInvoker;

            Container = container;
            ExtractSagaType();
        }
示例#9
0
        public void WaitLimitAndTimeout()
        {
            ServiceContainer services = new ServiceContainer();

            services.AddTransientPool <ISingleService, SingleService>(o =>
            {
                o.PoolMaxSize = 10;
                o.ExceedLimitWhenWaitTimeout = false;
                o.WaitAvailableDuration      = TimeSpan.FromMilliseconds(1500);
            });

            IContainerScope scope = services.CreateScope();

            for (int i = 0; i < 10; i++)
            {
                ISingleService service = services.Get <ISingleService>(scope);
                Assert.NotNull(service);
            }

            DateTime start = DateTime.UtcNow;

            Assert.Throws <NullReferenceException>(() => services.Get <ISingleService>(scope));
            DateTime end = DateTime.UtcNow;

            Assert.True(end - start > TimeSpan.FromMilliseconds(1490));
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="RequestInvokedEventArgs"/> class.
 /// </summary>
 /// <param name="scope">scope that was used to resolve the handler.</param>
 /// <param name="request">Request that was processed.</param>
 /// <exception cref="System.ArgumentNullException">
 /// scope
 /// or
 /// request
 /// </exception>
 public RequestInvokedEventArgs(IContainerScope scope, IRequest request)
 {
     if (scope == null) throw new ArgumentNullException("scope");
     if (request == null) throw new ArgumentNullException("request");
     Scope = scope;
     Request = request;
 }
示例#11
0
        static async Task Main(string[] args)
        {
            ServiceContainer services = new ServiceContainer();

            services.AddTransient <IServiceB, ServiceB>();
            services.AddTransient <IServiceC, ServiceC>();
            services.AddTransient <IServiceA, ServiceA>();
            services.AddTransient <IParentService, ParentService>();

            ITwinoServiceProvider provider = services.GetProvider();
            IContainerScope       scope    = provider.CreateScope();
            IParentService        service  = services.Get <IParentService>(scope);

            Console.WriteLine(service);
            Console.ReadLine();
            object s;
            Type   t = typeof(IParentService);

            while (true)
            {
                Stopwatch swx = new Stopwatch();
                swx.Start();
                for (int i = 0; i < 10000000; i++)
                {
                    s = provider.Get <IParentService>(); //scope);
                }

                swx.Stop();
                Console.WriteLine("Total : " + swx.ElapsedMilliseconds);
                Console.ReadLine();
            }
        }
示例#12
0
        public async void Single()
        {
            ServiceContainer services = new ServiceContainer();

            services.AddScoped <ISingleService, SingleService>();

            IContainerScope scope = services.CreateScope();

            ISingleService s1 = await services.Get <ISingleService>(scope);

            s1.Foo = "a";

            ISingleService s2 = await services.Get <ISingleService>(scope);

            Assert.Equal(s1.Foo, s2.Foo);

            //scopeless should throw error
            await Assert.ThrowsAsync <InvalidOperationException>(async() => await services.Get <ISingleService>());

            //another scope should not equal
            IContainerScope scope2 = services.CreateScope();
            ISingleService  s4     = await services.Get <ISingleService>(scope2);

            Assert.NotEqual(s1.Foo, s4.Foo);
            Assert.NotEqual(s2.Foo, s4.Foo);
        }
示例#13
0
        /// <summary>
        /// Try gets the service from the container.
        /// </summary>
        public Task <bool> TryGet <TService>(out TService service, IContainerScope scope = null) where TService : class
        {
            bool result = TryGet(typeof(TService), out object o, scope).Result;

            service = (TService)o;
            return(Task.FromResult(result));
        }
 /// <summary>
 ///     Initializes a new instance of the <see cref="ScopedTaskEventArgs" /> class.
 /// </summary>
 /// <param name="taskService">The task service.</param>
 /// <param name="scope">The scope.</param>
 /// <exception cref="System.ArgumentNullException">
 ///     taskService
 ///     or
 ///     scope
 /// </exception>
 public ScopedTaskEventArgs(object taskService, IContainerScope scope)
 {
     if (taskService == null) throw new ArgumentNullException("taskService");
     if (scope == null) throw new ArgumentNullException("scope");
     TaskService = taskService;
     Scope = scope;
 }
示例#15
0
        /// <summary>
        /// Creates instance of type.
        /// If it has constructor parameters, finds these parameters from the container
        /// </summary>
        public async Task <object> CreateInstance(Type type, IContainerScope scope = null)
        {
            ConstructorInfo constructor = type.GetConstructors()[0];

            ParameterInfo[] parameters = constructor.GetParameters();

            //if parameterless create directly and return
            if (parameters.Length == 0)
            {
                return(Activator.CreateInstance(type));
            }

            object[] values = new object[parameters.Length];

            //find all parameters from the container
            for (int i = 0; i < parameters.Length; i++)
            {
                ParameterInfo parameter = parameters[i];
                object        value     = await Get(parameter.ParameterType, scope);

                values[i] = value;
            }

            //create with parameters found from the container
            return(Activator.CreateInstance(type, values));
        }
示例#16
0
        /// <summary>
        /// Waits until an item is available.
        /// If any available item cannot be found, creates new if exceed possible. Otherwise returns null
        /// </summary>
        private async Task WaitForAvailable(IContainerScope scope, TaskCompletionSource <PoolServiceDescriptor <TService> > state)
        {
            //try to get when available
            if (Options.WaitAvailableDuration > TimeSpan.Zero)
            {
                DateTime waitMax = DateTime.UtcNow.Add(Options.WaitAvailableDuration);
                while (DateTime.UtcNow < waitMax)
                {
                    await Task.Delay(5);

                    PoolServiceDescriptor <TService> pdesc = GetFromCreatedItem(scope);

                    if (pdesc != null)
                    {
                        state.SetResult(pdesc);
                        return;
                    }
                }
            }

            //tried to get but timed out, if we can exceed limit, create new one and return
            PoolServiceDescriptor <TService> result = Options.ExceedLimitWhenWaitTimeout ? (await CreateNew(scope, true)) : null;

            state.SetResult(result);
        }
示例#17
0
        public void Single()
        {
            ServiceContainer services = new ServiceContainer();

            services.AddScoped <ISingleService, SingleService>();

            IContainerScope scope = services.CreateScope();

            ISingleService s1 = services.Get <ISingleService>(scope);

            s1.Foo = "a";

            ISingleService s2 = services.Get <ISingleService>(scope);

            Assert.Equal(s1.Foo, s2.Foo);

            //scopeless should throw error
            Assert.Throws <ScopeException>(() => services.Get <ISingleService>());

            //another scope should not equal
            IContainerScope scope2 = services.CreateScope();
            ISingleService  s4     = services.Get <ISingleService>(scope2);

            Assert.NotEqual(s1.Foo, s4.Foo);
            Assert.NotEqual(s2.Foo, s4.Foo);
        }
示例#18
0
        /// <summary>
        /// Creates new instance and adds to pool
        /// </summary>
        protected virtual async Task <PoolServiceDescriptor <TService> > CreateNew(IContainerScope scope, bool locked)
        {
            PoolServiceDescriptor <TService> descriptor = new PoolServiceDescriptor <TService>();

            descriptor.Locked         = locked;
            descriptor.Scope          = scope;
            descriptor.LockExpiration = DateTime.UtcNow.Add(Options.MaximumLockDuration);

            if (Type == ImplementationType.Scoped && scope != null)
            {
                //we couldn't find any created instance. create new.
                object instance = await Container.CreateInstance(typeof(TImplementation), scope);

                scope.PutItem(typeof(TService), instance);
                descriptor.Instance = (TService)instance;
            }
            else
            {
                object instance = await Container.CreateInstance(typeof(TImplementation), scope);

                descriptor.Instance = (TService)instance;
            }

            if (_func != null)
            {
                _func(descriptor.Instance);
            }

            lock (_descriptors)
                _descriptors.Add(descriptor);

            return(descriptor);
        }
        public Task <object> CreateConsumer(Type consumerType)
        {
            _scope = _implementationType == ImplementationType.Scoped ? _container.CreateScope() : null;
            object consumer = _container.Get(consumerType, _scope);

            return(Task.FromResult(consumer));
        }
示例#20
0
        public async Task LongRunning()
        {
            ServiceContainer services = new ServiceContainer();

            services.AddScopedPool <ISingleService, SingleService>();

            for (int i = 0; i < 50; i++)
            {
                IContainerScope scope1 = services.CreateScope();
                IContainerScope scope2 = services.CreateScope();

                ISingleService service1 = await services.Get <ISingleService>(scope1);

                ISingleService service2 = await services.Get <ISingleService>(scope2);

                Assert.NotNull(service1);
                Assert.NotNull(service2);
                Assert.NotEqual(service1, service2);

                await Task.Delay(10);

                scope1.Dispose();
                scope2.Dispose();
            }
        }
示例#21
0
        public async void Single()
        {
            ServiceContainer services = new ServiceContainer();

            services.AddTransient <ISingleService, SingleService>();

            ISingleService s1 = await services.Get <ISingleService>();

            s1.Foo = "a";

            //s1 and s2 should not be equal because they should be different instances
            ISingleService s2 = await services.Get <ISingleService>();

            Assert.NotEqual(s1.Foo, s2.Foo);

            //s1 or s2 should not equal to scoped transient instance
            IContainerScope scope = services.CreateScope();
            ISingleService  s3    = await services.Get <ISingleService>(scope);

            Assert.NotEqual(s1.Foo, s3.Foo);
            s3.Foo = "b";

            //two transient instances in same scope should not be equal
            ISingleService s4 = await services.Get <ISingleService>(scope);

            Assert.NotEqual(s1.Foo, s4.Foo);
            Assert.NotEqual(s3.Foo, s4.Foo);
        }
        internal object Get(Type serviceType, bool executedFromScope, IContainerScope scope = null)
        {
            //throw new NullReferenceException($"Could not get service from container: {typeof(TService).ToTypeString()}");
            //throw new KeyNotFoundException($"Service type is not found: {serviceType.ToTypeString()}");

            BuiltServiceDescriptor descriptor = _services[serviceType];

            if (descriptor.IsPool)
            {
                return(GetFromPool(descriptor, scope));
            }

            if (descriptor.Implementation == ImplementationType.Scoped && scope == null)
            {
                throw new ScopeException($"{serviceType.ToTypeString()} is registered as scoped service but trying to create instance when scope is null");
            }

            if (descriptor.Instance != null)
            {
                return(ApplyAfterGet(descriptor, descriptor.Instance));
            }

            object service;

            if (!executedFromScope && scope != null && descriptor.Implementation == ImplementationType.Scoped)
            {
                service = scope.Get(serviceType);
            }
            else
            {
                service = descriptor.CreateInstance(this, scope);
            }

            return(ApplyAfterGet(descriptor, service));
        }
示例#23
0
        public void MultipleNestedDoubleParameter()
        {
            ServiceContainer services = new ServiceContainer();

            services.AddScoped <INestParentService, NestParentService>();
            services.AddScoped <ISingleService, SingleService>();
            services.AddScoped <IParentService, ParentService>();
            services.AddScoped <IFirstChildService, FirstChildService>();
            services.AddScoped <ISecondChildService, SecondChildService>();

            IContainerScope scope = services.CreateScope();

            INestParentService nest = services.Get <INestParentService>(scope);

            nest.Foo               = "nest";
            nest.Parent.Foo        = "parent";
            nest.Parent.First.Foo  = "first";
            nest.Parent.Second.Foo = "second";
            nest.Single.Foo        = "single";

            INestParentService n1 = services.Get <INestParentService>(scope);

            Assert.Equal(nest.Foo, n1.Foo);
            Assert.Equal(nest.Single.Foo, n1.Single.Foo);
            Assert.Equal(nest.Parent.Foo, n1.Parent.Foo);
            Assert.Equal(nest.Parent.First.Foo, n1.Parent.First.Foo);
            Assert.Equal(nest.Parent.Second.Foo, n1.Parent.Second.Foo);

            IParentService parent = services.Get <IParentService>(scope);

            Assert.Equal(nest.Parent.Foo, parent.Foo);
            Assert.Equal(nest.Parent.First.Foo, parent.First.Foo);
            Assert.Equal(nest.Parent.Second.Foo, parent.Second.Foo);

            ISingleService single = services.Get <ISingleService>(scope);

            Assert.Equal(nest.Single.Foo, single.Foo);

            IFirstChildService first = services.Get <IFirstChildService>(scope);

            Assert.Equal(nest.Parent.First.Foo, first.Foo);

            ISecondChildService second = services.Get <ISecondChildService>(scope);

            Assert.Equal(nest.Parent.Second.Foo, second.Foo);

            //scopeless should throw error
            Assert.Throws <ScopeException>(() => services.Get <INestParentService>());

            //another scope should not equal
            IContainerScope    scope2 = services.CreateScope();
            INestParentService n3     = services.Get <INestParentService>(scope2);

            Assert.NotEqual(nest.Foo, n3.Foo);
            Assert.NotEqual(nest.Single.Foo, n3.Single.Foo);
            Assert.NotEqual(nest.Parent.Foo, n3.Parent.Foo);
            Assert.NotEqual(nest.Parent.First.Foo, n3.Parent.First.Foo);
            Assert.NotEqual(nest.Parent.Second.Foo, n3.Parent.Second.Foo);
        }
示例#24
0
 public MessageHandlersNexus(IContainerScope container,BusAuditor auditor,ConfigureHost host)
 {
     container.MustNotBeNull();
     _container = container;
     _auditor = auditor;
     _host = host;
     _error = host.GetStorage<IFailedMessagesQueue>();
 }
 public void Consumed(Exception error)
 {
     if (_scope != null)
     {
         _scope.Dispose();
         _scope = null;
     }
 }
示例#26
0
 /// <summary>
 ///     Created a new instance of <see cref="ScopeCreatedEventArgs" />.
 /// </summary>
 /// <param name="scope">created scope</param>
 public ScopeCreatedEventArgs(IContainerScope scope)
 {
     if (scope == null)
     {
         throw new ArgumentNullException(nameof(scope));
     }
     Scope = scope;
 }
示例#27
0
        public DiContainer(IContainerScope scope, ContainerOverrides overrides)
        {
            overrides.RegisterInstance(this, new RegistrationOptions().ExternallyOwned().As <IDependencyContainer>().As <IDependencyResolver>());

            _scope     = scope;
            _overrides = overrides;
            AddDisposable(_scope);
        }
示例#28
0
 internal ServiceBus(IContainerScope container,DispatcherClient client, ConfigureHost host,IReceiveServerMessages receiver)
 {
     Container = container;
     _client = client;
     _host = host;
     _receiver = receiver;
     _endpoints = host.Endpoints;
 }
示例#29
0
 public MessageHandlersNexus(IContainerScope container, BusAuditor auditor, ConfigureHost host)
 {
     container.MustNotBeNull();
     _container = container;
     _auditor   = auditor;
     _host      = host;
     _error     = host.GetStorage <IFailedMessagesQueue>();
 }
 public HandlerTypeInvokerTests()
 {
     _di  = Substitute.For <IContainerScope>();
     _err = Substitute.For <IFailedMessagesQueue>();
     _di.BeginLifetimeScope().Returns(_di);
     _handler = new MyHandler();
     _di.Resolve(typeof(MyHandler)).Returns(_handler);
     _sut = new HandlerTypeInvoker(typeof(MyHandler), _di, new BusAuditor(NullStorage.Instance), _err);
 }
 public HandlerTypeInvokerTests()
 {
     _di = Substitute.For<IContainerScope>();
     _err = Substitute.For<IFailedMessagesQueue>();
     _di.BeginLifetimeScope().Returns(_di);
     _handler=new MyHandler();
     _di.Resolve(typeof (MyHandler)).Returns(_handler);
     _sut =new HandlerTypeInvoker(typeof(MyHandler),_di,new BusAuditor(NullStorage.Instance), _err);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ScopeClosingEventArgs"/> class.
 /// </summary>
 /// <param name="scope">scope that is being closed.</param>
 /// <param name="successful">job was executed successfully.</param>
 /// <exception cref="System.ArgumentNullException">scope</exception>
 public ScopeClosingEventArgs(IContainerScope scope, bool successful)
 {
     if (scope == null)
     {
         throw new ArgumentNullException("scope");
     }
     Scope      = scope;
     Successful = successful;
 }
示例#33
0
 public HandlerTypeInvoker(Type handlerType, IContainerScope container,BusAuditor auditor,IFailedMessagesQueue errors)
 {
     handlerType.MustNotBeNull();
     container.MustNotBeNull();
     _handlerType = handlerType;
     _container = container;
     _auditor = auditor;
     _errors = errors;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="QueryExecutedEventArgs"/> class.
        /// </summary>
        /// <param name="scope">Scope used to resolve the handler.</param>
        /// <param name="query">Query to execute.</param>
        /// <param name="handler">Query handler that executed the query (implements <see cref="IQueryHandler{TQuery,TResult}"/>).</param>
        /// <exception cref="System.ArgumentNullException">
        /// scope
        /// or
        /// query
        /// </exception>
        public QueryExecutedEventArgs(IContainerScope scope, IQuery query, object handler)
        {
            if (scope == null) throw new ArgumentNullException("scope");
            if (query == null) throw new ArgumentNullException("query");

            Scope = scope;
            Query = query;
            Handler = handler;
        }
示例#35
0
 public HandlerTypeInvoker(Type handlerType, IContainerScope container, BusAuditor auditor, IFailedMessagesQueue errors)
 {
     handlerType.MustNotBeNull();
     container.MustNotBeNull();
     _handlerType = handlerType;
     _container   = container;
     _auditor     = auditor;
     _errors      = errors;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="EventPublishedEventArgs"/> class.
        /// </summary>
        /// <param name="scope">Scope used to resolve subscribers.</param>
        /// <param name="applicationEvent">Published event.</param>
        /// <param name="successful">All handlers processed the event successfully.</param>
        /// <exception cref="System.ArgumentNullException">
        /// scope
        /// or
        /// applicationEvent
        /// </exception>
        public EventPublishedEventArgs(IContainerScope scope, ApplicationEvent applicationEvent, bool successful)
        {
            if (scope == null) throw new ArgumentNullException("scope");
            if (applicationEvent == null) throw new ArgumentNullException("applicationEvent");

            Scope = scope;
            ApplicationEvent = applicationEvent;
            Successful = successful;
        }
        /// <summary>
        ///     Initializes a new instance of the <see cref="EventPublishedEventArgs" /> class.
        /// </summary>
        /// <param name="scope">Scope used to resolve subscribers.</param>
        /// <param name="applicationEvent">Published event.</param>
        /// <param name="successful">All handlers processed the event successfully.</param>
        /// <param name="eventInfo"></param>
        /// <exception cref="System.ArgumentNullException">
        ///     scope
        ///     or
        ///     applicationEvent
        /// </exception>
        public EventPublishedEventArgs(IContainerScope scope, ApplicationEvent applicationEvent, bool successful,
            IReadOnlyCollection<EventHandlerInfo> eventInfo)
        {
            if (applicationEvent == null) throw new ArgumentNullException("applicationEvent");

            Scope = scope;
            ApplicationEvent = applicationEvent;
            Successful = successful;
            Handlers = eventInfo;
        }
        public bool TryGet <TService>(out TService service, IContainerScope scope = null) where TService : class
        {
            if (!Contains <TService>())
            {
                service = null;
                return(false);
            }

            service = Get <TService>(scope);
            return(true);
        }
        public bool TryGet(Type serviceType, out object service, IContainerScope scope = null)
        {
            if (!Contains(serviceType))
            {
                service = null;
                return(false);
            }

            service = Get(serviceType);
            return(true);
        }
示例#40
0
            public void Prepare()
            {
                var targets = new TargetContainer();

                targets.RegisterType <ScopedTransient, ITransient1>();
                targets.RegisterType <ScopedCombined1, ICombined1>();
                targets.RegisterType <ScopedCombined2, ICombined2>();
                targets.RegisterType <ScopedCombined3, ICombined3>();
                this.child      = new OverridingContainer(this.parent, targets);
                this.childScope = this.child.CreateScope();
            }
示例#41
0
        public BaseSagaTests()
        {
            LogManager.OutputToTrace();
            _invoker = Substitute.For<IHandlerTypeInvoker>();
            _di = Substitute.For<IContainerScope>();
            _bus = Substitute.For<IDispatchMessages>();
            _handler = new Handler(_bus);
            _storage = Substitute.For<IStoreSagaState>();
            _saga = new MySagaState();

            this.Setup();

           
        }
示例#42
0
        internal EndpointConfig[] Build(ConfigureHost host, IContainerScope container, BusAuditor auditor) 
            => _points.Select(ec =>
        {
            var ep = ec.Key;
            var nexus = new MessageHandlersNexus(container,auditor,host);
            nexus.Add(host.Handlers.Where(ep.CanHandle).ToArray());

            var processor = new ProcessingService(host.GetStorage<IStoreUnhandledMessages>(), () => new MessageProcessor(nexus), auditor,host.GetStorage<IFailedMessagesQueue>());
            ec.Value(processor);

            var config = new EndpointConfig(processor);
            config.Id = new EndpointId(ep.Name, host.HostName);
            config.HandledMessagesTypes = nexus.GetMessageTypes().ToArray();
            processor.Name = config.Id;
            return config;
        }).ToArray();
示例#43
0
        public dynamic InstantiateHandler(IContainerScope resolver)
        {
            dynamic handler = null;
            try
            {
                handler = resolver.Resolve(HandlerType);
            }
            catch (Exception ex)
            {
                throw new DiContainerException(HandlerType, ex);
            }

            if (handler == null)
            {
                throw new DiContainerException(HandlerType, null);
            }
            return handler;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ScopeCreatedEventArgs"/> class.
 /// </summary>
 /// <param name="scope">That that will be used to resolve job.</param>
 /// <exception cref="System.ArgumentNullException">scope</exception>
 public ScopeCreatedEventArgs(IContainerScope scope)
 {
     if (scope == null) throw new ArgumentNullException("scope");
     Scope = scope;
 }
示例#45
0
 public SagaStarterExecutor(IHandlerTypeInvoker handlerInvoker, IContainerScope container) : base(handlerInvoker, container)
 {
 }
示例#46
0
 public static void Register(IContainerScope container)
 {
     container.MustNotBeNull();
     _inst = container;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ScopeClosingEventArgs"/> class.
 /// </summary>
 /// <param name="scope">scope that is being closed.</param>
 /// <param name="successful">job was executed successfully.</param>
 /// <exception cref="System.ArgumentNullException">scope</exception>
 public ScopeClosingEventArgs(IContainerScope scope, bool successful)
 {
     if (scope == null) throw new ArgumentNullException("scope");
     Scope = scope;
     Successful = successful;
 }
 /// <summary>
 ///     Created a new instance of <see cref="ScopeCreatedEventArgs" />.
 /// </summary>
 /// <param name="scope">created scope</param>
 public ScopeClosingEventArgs(IContainerScope scope)
 {
     if (scope == null) throw new ArgumentNullException(nameof(scope));
     Scope = scope;
 }