public SampleService() { // Poor Man's Dependency Injection _dataService = new GetDataService(); _mapperService = new MapperService(); _validationInput = new ValidateInput(); }
/// <summary> /// Creating data controller /// </summary> /// <param name="postDataService">Post data to the database service</param> /// <param name="getDataService">Get data from the database service</param> public DataController(IPostDataService postDataService, IGetDataService getDataService, IUnitOfWork unitOfWork, IDecryptService decryptService) { if (postDataService == null) { throw new ArgumentNullException(nameof(postDataService), " was null."); } if (getDataService == null) { throw new ArgumentNullException(nameof(getDataService), " was null."); } if (unitOfWork == null) { throw new ArgumentNullException(nameof(unitOfWork), " was null."); } if (decryptService == null) { throw new ArgumentNullException(nameof(decryptService), " was null."); } _postDataService = postDataService; _getDataService = getDataService; _unitOfWork = unitOfWork; _decryptService = decryptService; }
// USED FOR TESTING public SampleService( IGetDataService dataService = null, IMapperService mapperService = null, IValidateInput validateInput = null) { // Poor Man's Dependency Injection _dataService = dataService ?? new GetDataService(); _mapperService = mapperService ?? new MapperService(); _validationInput = validateInput ?? new ValidateInput(); }
public BookType(ApplicationDbContext db, IDataLoaderContextAccessor accessor, IGetDataService dataService) { Field(x => x.Id); Field(x => x.Title); Field(x => x.DateOfPublication); // this is an example of when you want to load many records for the current record (many sales invoices for the single book) // this will get the bookIds of all the books you want to load and then load all the sales invoices for them in one call Field <ListGraphType <SalesInvoiceType>, IEnumerable <SalesInvoice> >() .Name("SalesInvoices") .ResolveAsync(ctx => { var loader = accessor.Context.GetOrAddCollectionBatchLoader <int, SalesInvoice>("GetSaleInvoicesByBookId", dataService.GetSalesInvoicesAsync); return(loader.LoadAsync(ctx.Source.Id)); }); // this is an example of when you want to load a single record corresonding to the current record (the author record for the current book) // this will get the bookIds of all the books you want to load and then load all the authors for them in one call Field <AuthorType, Author>() .Name("Author") .ResolveAsync(ctx => { var loader = accessor.Context.GetOrAddBatchLoader <int, Author>("GetAuthorsById", dataService.GetAuthorsByIdAsync); return(loader.LoadAsync(ctx.Source.AuthorId)); }); // this is an example of when you want to load a variable of a single record corresonding to the current record (the author name for the current book) // this will get the bookIds of all the books you want to load and then load all the authors for them in one call and then extracts the author's name Field <StringGraphType, String>() .Name("AuthorsName") .ResolveAsync(ctx => { var loader = accessor.Context.GetOrAddBatchLoader <int, String>("GetAuthorsName", dataService.GetAuthorsNameAsync); return(loader.LoadAsync(ctx.Source.AuthorId)); }); }
public GraphQLQuery(ApplicationDbContext db, IDataLoaderContextAccessor accessor, IGetDataService dataService) { Field <IntGraphType>().Name("helloworld").Description("getTopics3desc") .Argument <IntGraphType>("newArg", "newDesc") .Resolve( context => { int i = context.GetArgument <int>("newArg"); return(100000000 + i); // // Get or add a batch loader with the key "GetUsersById" // // The loader will call GetUsersByIdAsync for each batch of keys // var loader = accessor.Context.GetOrAddBatchLoader<int, User>("GetBooks", users.GetUsersByIdAsync); // // Add this UserId to the pending keys to fetch // // The task will complete once the GetUsersByIdAsync() returns with the batched results // return loader.LoadAsync(context.Source.UserId); }); Field <ListGraphType <AuthorType> >().Name("GetAuthors").Description("Get all Authors") .Resolve( context => { return(db.Authors); //.ToListAsync(); // Get or add a batch loader with the key "GetUsersById" // The loader will call GetUsersByIdAsync for each batch of keys // var loader = accessor.Context.GetOrAddBatchLoader<int, Author>("GetAuthors", dataService.GetAuthors); // // Add this UserId to the pending keys to fetch // // The task will complete once the GetUsersByIdAsync() returns with the batched results // return loader.LoadAsync(context..); }); Field <ListGraphType <BookType> >().Name("GetBooks").Description("Get list of books") .Argument <IntGraphType>("first", "limit") .Resolve( context => { int i = context.GetArgument <int>("first"); return(db.Books.Take(i)); // Get or add a batch loader with the key "GetUsersById" // The loader will call GetUsersByIdAsync for each batch of keys // var loader = accessor.Context.GetOrAddBatchLoader<int, Author>("GetBooks", dataService.GetBooksAsync); // // Add this UserId to the pending keys to fetch // // The task will complete once the GetUsersByIdAsync() returns with the batched results // return loader.LoadAsync(context.Source.); }); }
public GetDataController(IGetDataService <T> service) { this.service = service; }
public AuthorType(ApplicationDbContext db, IDataLoaderContextAccessor accessor, IGetDataService dataService) { Field(x => x.Id); Field(x => x.Name); Field(x => x.DateOfBirth); // Field<IntGraphType>( // "noOfFacts", // resolve: context => // { // return context.Source.Links.Count(); // // data.GetFriends(context.Source) // }); // Field<ListGraphType<BookType>>() // .Name("Books") // .ResolveAsync( // async context => // { // // Get or add a batch loader with the key "GetUsersById" // //The loader will call GetUsersByIdAsync for each batch of keys // var loader = accessor.Context.GetOrAddBatchLoader<int, Book>("GetBooksByAuthorId", dataService.GetBooksAsync); // // Add this UserId to the pending keys to fetch // // The task will complete once the GetUsersByIdAsync() returns with the batched results // return await loader.LoadAsync(context.Source.Id); // }); Field <ListGraphType <BookType>, IEnumerable <Book> >() .Name("Books") .ResolveAsync(ctx => { var loader = accessor.Context.GetOrAddCollectionBatchLoader <int, Book>("GetBooksByAuthorId", dataService.GetBooksAsync); return(loader.LoadAsync(ctx.Source.Id)); }); // } // , description: "primary facts"); // Field<ListGraphType<FactType>>("nonPrimaryFacts", // // arguments: new QueryArguments(new QueryArgument<IntGraphType> { Name = "id" }), // resolve: context => // { // return context.Source.Links.Where(l => !l.IsPrimaryTopic) // .Select(f => f.Fact).OrderByDescending(f => // f.Votes.Where(v => v.VoteChoice == VoteChoice.Upvote).Count() - // f.Votes.Where(v => v.VoteChoice == VoteChoice.Downvote).Count()); // } // , description: "primary facts"); // ApplicationUserType>( // "creator", // resolve: context => // { // Console.WriteLine("hello"); // return userManager.FindByIdAsync(context.Source.ApplicationUserId).Result; // },true ); // Field<ListGraphType<ApplicationUserType>>("applicationUserType", // arguments: new QueryArguments(new QueryArgument<IntGraphType> { Name = "id" }), // resolve: context => // { // var user = userManager.FindByIdAsync(context.Source.ApplicationUserId).Result; // return user; // } // , description: "Pineapple creator"); }
public GetDataServiceAdapter(NLog.ILogger logger, IGetDataService getDataService) { this.logger = logger; this.getDataService = getDataService; }
public HomeController(IGetDataService getDataService, IDisplayDataService displayDataService) { this.getDataService = getDataService ?? throw new ArgumentNullException(nameof(getDataService)); this.displayDataService = displayDataService ?? throw new ArgumentNullException(nameof(displayDataService)); }
public HtmlService(IGetDataService getDataService) { this.getDataService = getDataService ?? throw new ArgumentNullException(nameof(getDataService)); }