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

  • Home
  • SEARCH
  • 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 3213078
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T14:54:17+00:00 2026-05-17T14:54:17+00:00

I’m using StructureMap DI/IoC and I’ve got is a generic InMemory repository. Works great.

  • 0

I’m using StructureMap DI/IoC and I’ve got is a generic InMemory repository. Works great. I was wondering if it’s possible to define the initial data which each repository holds, when it’s requested?

Now, the first reaction is to do this in the constructor of the class – but I’m using a Generic Repository .. so i don’t know what type of class will be instantiated. Next, I could subclass the GenericRepository and then create a constructor – sure 🙂 That would work .. but i was trying to avoid creating a single class for each repository, when the GenericRepository is more or less doing everything I want 🙂 (yes, there’s some specific instances which I do subclass, etc.. but lets keep this post, simple).

So, is there a way to say

  1. Create an instance of InMemoryGenericRepository when ever an IRepository is requested
  2. Now, call this static method (which populates that Repo instant) : Foo(IRepository repository) { … } which of course passes in the instance that was just created by StructureMap.
  • 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-17T14:54:17+00:00Added an answer on May 17, 2026 at 2:54 pm

    The answer is StructureMap Inception :: .OnCreation(Action).

    so with my example, above…

    For<IRepository<Post>>()
        .Use<InMemory.GenericRepository<Post>>()
        .OnCreation(x => x.Add(InMemoryData.CreatePostStubs());
    

    Firstly, the static method CreatePostStubs() returns an ICollection<Post> which then gets passed into a method called Add to my newly created GenericRepository<Post> instance. This, in effect, adds all the stubs to my in-memory repository.

    FUNKY !!

    So funky, it’s time for a Funky Cold Medina…

    alt text

    Cheers to @Zor for starting me off on the right direction …

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

Sidebar

Related Questions

No related questions found

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.