Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 841323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T05:46:32+00:00 2026-05-15T05:46:32+00:00

I am not sure how to use StructureMap to scan for all repositories in

  • 0

I am not sure how to use StructureMap to scan for all repositories in a particular namespace. Most repositories take the form:

namespace CPOP.Infrastructure.Repositories
{
    public class PatientRepository : LinqRepository<Patient>, IPatientRepository
    {
    }
}

namespace CPOP.Infrastructure.Repositories
{
    public class LinqRepository<T> : Repository<T>, ILinqRepository<T>
    {
    }
}

namespace CPOP.Domain.Contracts.Repositories
{
    public interface IPatientRepository : ILinqRepository<Patient>
    {
    }
}

I tried:

x.Scan(scanner =>
{
    scanner.Assembly(Assembly.GetExecutingAssembly());
    scanner.ConnectImplementationsToTypesClosing(typeof(ILinqRepository<>));
})

But, it only picks up the LinqRepository class. What’s the best way to pick up the various repositories I’ll be dumping in there?

And, as per Joshua’s reuest, here’s an example of use:

namespace CPOP.ApplicationServices
{
    public class PatientTasks : IPatientTasks
    {
        private readonly IPatientRepository _patientRepository;

        public PatientTasks(IPatientRepository patientRepository)
        {
            _patientRepository = patientRepository;
        }

        public Patient GetPatientById(int patientId)
        {
            int userId; // get userId from authentication mechanism

            return _patientRepository.FindOne(new PatientByIdSpecification(patientId));
        }

        public IEnumerable<Patient> GetAll()
        {
            int userId; // get userId from authentication mechanism

            return _patientRepository.FindAll();
        }

    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T05:46:33+00:00Added an answer on May 15, 2026 at 5:46 am

    This can be done with just one line of code in your configuration. Assuming you have this:

    Entities:
    – Customer
    – Order

    And have a generic repository model like this:

    • Repository : IRepository

    And have a app services that look like:

    public AppService(IRepository<Customer> custRepo, IRepository<Order> orderRepo)
    

    You would have something like this. Notice the bit about using the scanner to hook up your custom repositories.

    public class SmRegistry : Registry
        {
            public SmRegistry()
            {
                For(typeof (IRepository<>))
                    .Use(typeof (Repository<>));
    
                //using this will find any custom repos, like CustomerRepository : Repository<Customer>
                //Scan(scanner =>
                //         {
                //             scanner.TheCallingAssembly();
                //             scanner.ConnectImplementationsToTypesClosing(typeof (IRepository<>));
    
                //         });
            }
        }
    

    Assuming your Repositories are defined in some other assembly from your application, you can use Registries to hook it all together. Check out this post:

    http://blog.coreycoogan.com/2010/05/24/using-structuremap-to-configure-applications-and-components/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm not sure how to use composite key. My Categories table has CategoryId (PK,FK),
I am not sure how to use a single port at server side simultaneously
I'm not sure how to use the Unproject method provided by GLM. Specifically, in
I'm using JPA but I'm not sure how to use it for relation between
I am working on threading in MFC..I am not sure how to use threading..
I'm using http://cloud.github.com/downloads/emberjs/ember.js/ember-0.9.5.js and I'm not sure how to use the mouseenter and mouseleave
Not sure if this is possible: I want to use datatables to manipulate my
Not sure if this counts as programming related, it's a tool that I use.
I'm not sure when it is appropriate to use a cursor. I need to
I'm not sure what kind of terminology to use in this so please edit

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.