/// <summary>
        /// Creates a new DbContext and saves a reference to the old one, which will be restored when the
        /// StackFrame object is disposed. This ensures that "attached" entities are not leaked outside of the service.
        /// </summary>
        /// <returns>
        /// The <see cref="StackFrame"/> object responsible for disposing the new DbContext and restoring the old one
        /// </returns>
        protected StackFrame NewDbContextScope()
        {
            var previousDbContext = this.DbContext;

            this.DbContext = dbContextFactory.Create();
            return(new StackFrame(() =>
            {
                this.DbContext.Dispose();
                this.DbContext = previousDbContext;
            }));
        }
        public DiffApiTests()
        {
            // Injection container.
            this.kernel = new StandardKernel();
            this.kernel.Load <WebApi.Injection.NinjectBindings>();

            // Host.
            this.server = new SelfHostHttpServer((c) =>
            {
                WebApi.WebApiConfig.Register(c);
                c.DependencyResolver = new NinjectDependencyResolver(this.kernel);
            }, ApiBaseUrl);

            this.dbContext = this.kernel.Get <IDataEntities>();
        }
 /// <summary>
 /// Initializes a <see cref="DataService"/> instance with an injected <see cref="IDataEntitiesFactory"/> instance.
 /// </summary>
 /// <param name="dataEntitiesFactory"></param>
 public DataService(IDataEntitiesFactory dataEntitiesFactory)
 {
     this.dbContextFactory = dataEntitiesFactory;
     this.DbContext        = this.dbContextFactory.Create();
 }