logo
down
shadow

Compositon and Repository pattern


Compositon and Repository pattern

Content Index :

Compositon and Repository pattern
Tag : chash , By : David
Date : January 12 2021, 09:11 PM

fixed the issue. Will look into that further Your interface should describe all the methods you wish to be exposed. Your interfaces describe what a given class will implement, not how its implemented, thus not exposing the state of the class. This is good as it allows you to have several classes inherit from this interface and implement the same methods in different ways.
In your case, you want the ability to "Add" from your CategoryRepository. Luckily for you, you already have an interface for this, IBloggingRepository.
// Implementation of the repository
// Does not expose Add to the ICategoryRepository !!!
public class CategoryRepository : ICategoryRepository, IBloggingRepository
{
    private readonly DataContext _context;

    private readonly IBloggingRepository _bloggingRepo;

    public CategoryRepository(DataContext context, IBloggingRepository bloggingRepository) 
    {
        _context = context;
        _bloggingRepo = bloggingRepository;
    }
    // The implementation of the Add method
    public void Add<T>(T entity) where T : class
    {
        _bloggingRepo.Add(entity);
    }
}
// Exposes the IBloggingRepository methods to ICategoryRepository
public interface ICategoryRepository : IBloggingRepository
{
}

// Implementation of the repository
public class CategoryRepository : ICategoryRepository
{
    private readonly DataContext _context;

    private readonly IBloggingRepository _bloggingRepo;

    public CategoryRepository(DataContext context, IBloggingRepository bloggingRepository) 
    {
        _context = context;
        _bloggingRepo = bloggingRepository;
    }
    // The implementation of the Add method
    public void Add<T>(T entity) where T : class
    {
        _bloggingRepo.Add(entity);
    }
}
// Some model to be added to the repository
// Just for demonstration purposes
public class Blog
{
    public Blog() { }
}


public class CategoryController : Controller
{
    private readonly ICategoryRepository _categoryRepo;

    public CategoryController(ICategoryRepository categoryRepo)
    {
        _categoryRepo = categoryRepo;
    }

    public async Task<IActionResult> SaveCategory()
    {
       // _categoryRepo.bloggingRepo.Add();
       return await Task.Run(() => 
       {
           Blog blog = new Blog();
           _categoryRepo.Add(blog);
           // return IActionResult;

       }).ConfigureAwait(false);
    }
}

Comments
No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

Tag : chash , By : k19k
Date : March 29 2020, 07:55 AM
Hope this helps We have been doing a lot of thinking recently at my work and came across a few articles that helped us visualize and design our repositories in a consistent manner.
From what we found out one of the better practices is to create one repository per aggregate root. An aggregate root would be an Entity type where you need to reference that entity type to reach child value types. Only an Entity type could be queried from the database and any child Value types would need to be traversed from the Entity.

Chaining methods using generics and compositon


Tag : chash , By : Mariocki
Date : March 29 2020, 07:55 AM
wish helps you I'm trying to model series of "phases" C#, where each phase has an input and output, and where they can be chained together, with the output of phase 1 becoming the input of phase 2. I thought it might look something like this, but I didn't know what to use in place of the ???. , You could try with two classes:
public class OutputOfPhase<TOutput>
{
}

public class Phase<TInput, TOutput> : OutputOfPhase<TOutput>
{
      private OutputOfPhase<TInput> prerequisite;

      public Phase(OutputOfPhase<TInput> prereq, Func<TInput, TOutput> work)
      {
      /* ... */
      }
}
Phase<int, long> p1 = new Phase<int, long>(null, p => p * 1000L);
Phase<long, double> p2 = new Phase<long, double>(p1, p => p / 2.0);

how to prove the associative law of the compositon operation (.) in Haskell


Tag : haskell , By : user184415
Date : March 29 2020, 07:55 AM
should help you out say , , You can define the composition operator yourself as follows:
(.) :: (b -> c) -> (a -> b) -> a -> c
g . f = \x -> g (f x)
lhs = h . (g . f)
    = \x -> h ((g . f) x)         -- substitution
    = \x -> h ((\y -> g (f y)) x) -- substitution
    = \x -> h (g (f x))           -- beta reduction

rhs = (h . g) . f
    = \x -> (h . g) (f x)         -- substitution
    = \x -> (\y -> h (g y)) (f x) -- substitution
    = \x -> h (g (f x))           -- beta reduction

How to do train composition - compositon of classes


Tag : java , By : kokok13
Date : March 29 2020, 07:55 AM
I hope this helps you . Im not sure about what are you asking, but I will try to give you my aproximation:
You need to create a composite object where every object has an unique ID and need to pass some validations.

RollingStock freightCoach = StoregeManager.getFreightCoach();
RollingStock specialCoach = StoregeManager.getSpecialCoach();
RollingStock dieselEngine = StoregeManager.getDieselEngine();

// Check if they are null or throw an exception if has no more elements. Maybe from BBDD or from where you want

Composer.compone()
.add(dieselEngine)
.add(freightCoach)
.add(specialCoach)
.build()


public class Composer {

    private StoregeManager storeManager; //Injected or initialized, as you want.
    private static Train train;

    public Composer build(){
        train = new Train;
        return this;
    }

    public Composer add(RollingStock rs) {
        if(rs.isValid(train))
            train.add(rs);
        return this;
    }

    public RollingStock[] build() {
        storageManager.ckeckTrain(train);
        return train;
    }
}

overloaded member function error while doing compositon c++


Tag : cpp , By : Mahesh
Date : March 29 2020, 07:55 AM
Related Posts Related QUESTIONS :
  • Is this a good way to determine OS Architecture?
  • How to create a tree-view preferences dialog type of interface in C#?
  • Searching directories for tons of files?
  • Can I have a method returning IEnumerator<T> and use it in a foreach loop?
  • Why can't I have abstract static methods in C#?
  • Displaying ad content from Respose.WriteFile()/ Response.ContentType
  • Convert integers to written numbers
  • Absolute path back to web-relative path
  • How can we generate getters and setters in Visual Studio?
  • Bringing Window to the Front in C# using Win32 API
  • Possible to "spin off" several GUI threads? (Not halting the system at Application.Run)
  • Reading a C/C++ data structure in C# from a byte array
  • How should I translate from screen space coordinates to image space coordinates in a WinForms PictureBox?
  • Setting Objects to Null/Nothing after use in .NET
  • Converting ARBG to RGB with alpha blending
  • Is it better to create Model classes or stick with generic database utility class?
  • Passing enum type to Converter with integer value
  • Pool of objects with objects that are already on the scene in advance
  • StatusBar text fade-out when binding using Caliburn.Micro
  • Queryfilter on ApplicationUser in OnModelCreating in ApplicationDbContext creates StackOverflowException
  • How to get record form a different table based on a value from first table with linq expression?
  • Show data in Grid from returned model
  • Using Attributes to Override Data Model Conventions
  • Basic OOP console calculator, result Error
  • Multiple using statements with if condition
  • How do i increase a number by 1 in every line that contain the number 1
  • Add binding to elements that are created in codebehind
  • How to add a column in an existing AspNetUsers table
  • Order a list of elements with another list of doubles
  • How to setup a NuGet package to copy content files to output build directory?
  • In SignalR Core using ChannelWriter: Do I need to call TryComplete twice if there's an exception?
  • C# GetProcessesByName: issue with colon
  • c# wpf | create complex object with user-defined name to Serialize into JSON
  • How can I get a instance of a generic list with reflection?
  • WPF XAML - Design time and visibility of textbox
  • EF Core and MySql query is too slow
  • Getting Registered App Display Name from an App Id
  • How to get all variables from a string
  • Delete entity with all childs connected
  • Azure Build agent cant´t find class library referance
  • Initialize Nested Dictionaries in c#
  • .Net Core Binding
  • Generic event test method, preventing code duplication
  • How do I keep the ellipses in the center when the screen is resized
  • How to require a property using JsonSchema.NET?
  • C# XDocument Element/Elements returns null
  • Autofac keyed service with IEnumerable relationship type
  • Installing EntityFramework via NuGet manager
  • Always Check if there is Internet Connection Xamarin forms
  • WCF OneWay service slows down when aspNetCompatibilityEnabled is set to false
  • Can we use JsonRequestBehavior.AllowGet with [HttpPost] attribute?
  • How to customize the Setup wizard with custom forms in Visual Studio setup project
  • C# ASP.NET - Use method from another class to create labels
  • C# List IList or IEnumerable as argument
  • Parsing File with C# And Replace method
  • Losing special unicode characters in encryption (C#)
  • Getting stored procedure returned value instead of row affected
  • How can I construct HTML using NameValuePair in android?
  • Loading a pop up page in ASP.net through a js file
  • How to pass alert or notification message from controller to View?
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com