Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Custom Repositories

Omar Piani edited this page Feb 14, 2018 · 2 revisions

This example explain how to add a method to all the repositories you have configured for type of "Contact"

 public class EmailRepository : ConfigurationBasedRepository<Contact, string>
    {
        public EmailRepository(ISharpRepositoryConfiguration configuration, string repositoryName = null) : base(configuration, repositoryName)
        {
        }

        public IEnumerable<string> GetAllMails()
        {
            return this.GetAll().SelectMany(c => c.Emails).Select(m => m.EmailAddress).Distinct();
        }
    }

you have to add to your service container your custom repository.

For example in .NET Core in Startup.cs

services.AddTransient<EmailRepository>(r => new EmailRepository(RepositoryFactory.BuildSharpRepositoryConfiguation(Configuration.GetSection("sharpRepository"))));

will instantiate EmailRepository how you configured in your appsettings.json and inject in your controller constructor

public EmailsController(EmailRepository repository)

Clone this wiki locally

Morty Proxy This is a proxified and sanitized view of the page, visit original site.