示例#1
0
        public override void Load()
        {
            var requestLogger = new EmptyInterceptor();

#if DEBUG
            requestLogger = new SQLDebugOutputInterceptor();
#endif

            Bind <IUserRepository>().To <UserRepository>();
            Bind <IEventRepository>().To <EventRepository>();
            Bind <ISubscriptionRepository>().To <SubscriptionRepository>();
            Bind <IEpcisRequestRepository>().To <EpcisRequestRepository>();
            Bind <IAuditLogRepository>().To <AuditLogRepository>();

            Bind <ILogStore>().To <LogStore>();

            // NHibernate Session binding
            Bind <ISessionFactory>().ToConstant(SessionProvider.SetupFactory(ConnectionString)).InSingletonScope();
            Bind <ISession>().ToMethod(ctx => ctx.Kernel.Get <ISessionFactory>().OpenSession(requestLogger)).UsingScope(Scope);
            Bind <ITransaction>().ToMethod(ctx => ctx.Kernel.Get <ISession>().BeginTransaction()).UsingScope(Scope);

            // Bindings for subscription runners
            Bind <ISession>().ToMethod(ctx => ctx.Kernel.Get <ISessionFactory>().OpenSession(requestLogger)).WhenInjectedInto <ISubscriptionRunner>();

            Bind <ICommitTransactionInterceptor>().To <NHibernateCommitTransactionInterceptor>();
        }
示例#2
0
        private Task CanSetInterceptorAsync <T>(T sb) where T : ISessionBuilder <T>
        {
            try
            {
                var sbType = sb.GetType().Name;
                // Do not use .Instance here, we want another instance.
                var interceptor = new EmptyInterceptor();
                var options     = DebugSessionFactory.GetCreationOptions(sb);

                Assert.AreEqual(Sfi.Interceptor, options.SessionInterceptor, $"{sbType}: Initial value");
                var fsb = sb.Interceptor(interceptor);
                Assert.AreEqual(interceptor, options.SessionInterceptor, $"{sbType}: After call with an interceptor");
                Assert.AreEqual(sb, fsb, $"{sbType}: Unexpected fluent return after call with an interceptor");

                if (sb is ISharedSessionBuilder ssb)
                {
                    var fssb = ssb.Interceptor();
                    Assert.AreEqual(EmptyInterceptor.Instance, options.SessionInterceptor, $"{sbType}: After call with shared interceptor");
                    Assert.AreEqual(sb, fssb, $"{sbType}: Unexpected fluent return on shared");
                }

                Assert.Throws <ArgumentNullException>(() => sb.Interceptor(null), $"{sbType}: After call with null");

                fsb = sb.NoInterceptor();
                Assert.AreEqual(EmptyInterceptor.Instance, options.SessionInterceptor, $"{sbType}: After no call");
                Assert.AreEqual(sb, fsb, $"{sbType}: Unexpected fluent return after no call");
                return(Task.CompletedTask);
            }
            catch (Exception ex)
            {
                return(Task.FromException <object>(ex));
            }
        }
示例#3
0
        private void CanSetInterceptor <T>(T sb) where T : ISessionBuilder <T>
        {
            var sbType = sb.GetType().Name;
            // Do not use .Instance here, we want another instance.
            var interceptor = new EmptyInterceptor();
            var options     = (ISessionCreationOptions)sb;

            Assert.AreEqual(sessions.Interceptor, options.SessionInterceptor, $"{sbType}: Initial value");
            var fsb = sb.Interceptor(interceptor);

            Assert.AreEqual(interceptor, options.SessionInterceptor, $"{sbType}: After call with an interceptor");
            Assert.AreEqual(sb, fsb, $"{sbType}: Unexpected fluent return after call with an interceptor");

            if (sb is ISharedSessionBuilder ssb)
            {
                var fssb = ssb.Interceptor();
                Assert.AreEqual(EmptyInterceptor.Instance, options.SessionInterceptor, $"{sbType}: After call with shared interceptor");
                Assert.AreEqual(sb, fssb, $"{sbType}: Unexpected fluent return on shared");
            }

            Assert.Throws <ArgumentNullException>(() => sb.Interceptor(null), $"{sbType}: After call with null");

            fsb = sb.NoInterceptor();
            Assert.AreEqual(EmptyInterceptor.Instance, options.SessionInterceptor, $"{sbType}: After no call");
            Assert.AreEqual(sb, fsb, $"{sbType}: Unexpected fluent return after no call");
        }