Skip to content

Commit

Permalink
feat: use DI for redis datasource
Browse files Browse the repository at this point in the history
Signed-off-by: Raymond Feng <[email protected]>
  • Loading branch information
raymondfeng committed Aug 28, 2018
1 parent bcead1b commit ae70344
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/repositories/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
// License text available at https://opensource.org/licenses/MIT

export * from './user.repository';
export * from './shopping-cart.repository';
5 changes: 3 additions & 2 deletions src/repositories/shopping-cart.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
import {DefaultKeyValueRepository} from '@loopback/repository';
import {ShoppingCart} from '../models/shopping-cart.model';
import {RedisDataSource} from '../datasources/redis.datasource';
import {inject} from '@loopback/context';

export class ShoppingCartRepository extends DefaultKeyValueRepository<
ShoppingCart
> {
constructor() {
super(ShoppingCart, new RedisDataSource());
constructor(@inject('datasources.redis') ds: RedisDataSource) {
super(ShoppingCart, ds);
}
}
5 changes: 3 additions & 2 deletions test/integration/shopping-cart.repository.integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

import {ShoppingCartRepository} from '../../src/repositories/shopping-cart.repository';
import {ShoppingCartRepository} from '../../src/repositories';
import {ShoppingCart} from '../../src/models';
import {expect} from '@loopback/testlab';
import {RedisDataSource} from '../../src/datasources';

describe('ShoppingCart KeyValue Repository', () => {
let repo: ShoppingCartRepository;
Expand All @@ -15,7 +16,7 @@ describe('ShoppingCart KeyValue Repository', () => {
before(() => {
cart1 = givenShoppingCart1();
cart2 = givenShoppingCart2();
repo = new ShoppingCartRepository();
repo = new ShoppingCartRepository(new RedisDataSource());
});

beforeEach(async () => {
Expand Down

0 comments on commit ae70344

Please sign in to comment.