コード例 #1
0
        internal BloggingDataService(IBloggingContext context)
        {
            _dbContext = context;

            Posts = new PostRepository(_dbContext.Posts);
            Blogs = new BlogRepository(_dbContext.Blogs);
        }
コード例 #2
0
    public async Task <Blog> Get(int id)
    {
        //validation goes here
        Blog blog = null;

        // Instantiage context only if needed and dispose immediately
        using (IBloggingContext context = _bloggingContextFactory.CreateContext())
        {
            blog = await context.Blogs.FindAsync(id);
        }
        //Do further processing without need of context.
        return(blog);
    }
コード例 #3
0
    public BlogControllerTest()
    {
        //creating seed objects
        var post = new Post()
        {
            PostId  = 1,
            Title   = "Some title",
            Content = "post contemt"
        };
        var blog = new Blog()
        {
            BlogId = 1,
            Url    = "google",
            Posts  = new List <Post>()
            {
                post
            }
        };

        //associating blog with post
        post.Blog   = blog;
        post.BlogId = blog.BlogId;
        var blogsMock = new List <Blog>()
        {
            blog
        }.AsDbSetMock();
        var postsMock = new List <Post>()
        {
            post
        }.AsDbSetMock();
        var contextMock = new Mock <IBloggingContext>();

        contextMock.Setup(m => m.Blogs).Returns(blogsMock.Object);
        contextMock.Setup(m => m.Posts).Returns(postsMock.Object);
        _context    = contextMock.Object;
        _controller = new BlogController(_context);
    }
コード例 #4
0
 public BlogService(IBloggingContext context)
 {
     _context = context;
 }
コード例 #5
0
ファイル: BlogService.cs プロジェクト: hobe/entityframework
 public BlogService(IBloggingContext context)
 {
     _context = context;
 }
コード例 #6
0
 public HomeController(IBloggingContext context)
 {
     _context = context;
 }
コード例 #7
0
 public BlogController(IBloggingContext bloggingContext)
 {
     this._context = bloggingContext;
 }