GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Evolutionary Developer

This view

  • Original page
  • New address

GeezerVison is showing evolutionarydeveloper.blogspot.com — ServiceStack.Redis and StructureMap

Tuesday, 8 April 2014

ServiceStack.Redis and StructureMap

I've tripped up on this a couple of times so I've just decided to layout the right way to make use of the ServiceStack.Redis client library when using StructureMap DI Container. The mistake I used to make was to have my controller or service depend upon an IRedisClient. StructureMap would be configured to provide an instance of an IRedisClient by invoking GetClient() on the whatever singleton instance of IRedisClientsManager I was using, usually the PooledRedisClientsManager. Much was learned from this SO answer.

This was a problem because it limited the re-usability of the consuming controller/service. Such a service might provide a method that used the injected IRedisClient to interact with the Redis instance. The IRedisClient implements IDisposable and should be wrapped in a using statement in order to release the resource and close the channel when it is has completed the task. In doing so, you make the method on the service non-idempotent: it has the side-effect of changing the state of the service by disposing of its injected IRedisClient instance. You are only able to successfully call the service method once, calling it a second time throws an exception.

The solution is fairly simple. Instead of having the service depend directly on the IRedisClient, the service instead needs to depend on the IRedisClientsManager. This then allows the service to call the GetClient() method on the IRedisClientsManager itself and create an instance of IRedisClient every time the method is called. Idempotency is achieved because a client of the service can call the method any number of times and not cause any unintended side-effects. The state of the service is no longer affected by disposing of its only instance of IRedisClient. The IRedisClient instances that are created are still disposed of, but the service has the ability to create a new one for itself.

The pattern is very similar to the RavenDB IDocumentStore and IDocumentSession that I am familiar with, so I surprised it took me so long to figure out!
Posted by Unknown at 13:18
Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest
Labels: dependency injection, redis, structuremap

41 comments:

  1. genga g13 September 2018 at 23:32

    This comment has been removed by the author.

    ReplyDelete
    Replies
      Reply
  2. Unknown11 October 2018 at 23:19

    Well done! Pleasant post! This truly helps me to discover the solutions for my inquiry. Trusting, that you will keep posting articles having heaps of valuable data. You're the best! 
    Python training in marathahalli | Python training institute in pune

    ReplyDelete
    Replies
      Reply
  3. jeeva15 October 2018 at 05:39

    Wow it is really wonderful and awesome thus it is very much useful for me to understand many concepts and helped me a lot. it is really explainable very well and i got more information from your blog.

    blueprism training in chennai | blueprism training in bangalore | blueprism training in pune | blueprism online training

    ReplyDelete
    Replies
      Reply
  4. Unknown16 October 2018 at 01:49

    Nice information, valuable and excellent design, as share good stuff with good ideas and concepts, lots of great information and inspiration, both of which I need, thanks to offer such a helpful information here.
    Java interview questions and answers | Core Java interview questions and answers

    ReplyDelete
    Replies
      Reply
  5. shalinipriya16 October 2018 at 02:06

    It was worth visiting your blog and I have bookmarked your blog. Hope to visit again

    Data Science Training in Chennai | Data Science training in anna nagar

    Data Science training in chennai | Data science training in Bangalore

    Data Science training in marathahalli | Data Science training in btm layout

    ReplyDelete
    Replies
      Reply
  6. kani17 December 2019 at 02:20

    nice..
    inplant training in chennai
    inplant training in chennai
    inplant training in chennai for it
    hosting
    india hosting
    india web hosting
    iran web hosting
    technology 11 great image sites like imgur hosting
    final year project dotnet server hacking what is web hosting
    macao web hosting

    ReplyDelete
    Replies
      Reply
  7. RIA Institute of Technology26 March 2020 at 21:59

    Thanks for sharing such a nice information with us...
    angular js training in bangalore

    ReplyDelete
    Replies
      Reply
  8. nizam16 May 2020 at 03:36

    you have selected such a nice topic and well explained

    AngularJS Training in Chennai | AngularJS Training in Anna Nagar | AngularJS Training in OMR | AngularJS Training in Porur | AngularJS Training in Tambaram | AngularJS Training in Velachery



    ReplyDelete
    Replies
      Reply
  9. Faizal22 May 2020 at 04:24

    This Technology Topics and contents are Amazing..I love to Learn more about this Topic...Keep doing more about this
    Java training in chennai | Java training in annanagar | Java training in omr | Java training in porur | Java training in tambaram | Java training in velachery

    ReplyDelete
    Replies
      Reply
  10. lavanya28 May 2020 at 09:12

    Nice article Thanks for sharing this article Wonderful information from this website Thanks !!!c Software Testing Training in Chennai | Software Testing Training in Anna Nagar | Software Testing Training in OMR | Software Testing Training in Porur | Software Testing Training in Tambaram | Software Testing Training in Velachery


    ReplyDelete
    Replies
      Reply
  11. subha5 June 2020 at 06:41

    Does your blog have a contact page? I’m having problems locating it but, I’d like to shoot you an email. I’ve got some recommendations for your blog you might be interested in hearing.share some more.
    Ai & Artificial Intelligence Course in Chennai
    PHP Training in Chennai
    Ethical Hacking Course in Chennai Blue Prism Training in Chennai
    UiPath Training in Chennai

    ReplyDelete
    Replies
      Reply
  12. rocky11 July 2020 at 00:40

    I'm interested your article for some more information are i like that your content.thank you so much. It helpful for me.
    Python Training in Chennai | Certification | Online Training Course | Python Training in Bangalore | Certification | Online Training Course | Python Training in Hyderabad | Certification | Online Training Course | Python Training in Coimbatore | Certification | Online Training Course | Python Training in Online | Python Certification Training Course




    ReplyDelete
    Replies
      Reply
  13. deiva5 August 2020 at 23:12

    Well Said, you have furnished the right information that will be useful to anyone at all time. Thanks for sharing your Ideas.
    java training in chennai

    java training in omr

    aws training in chennai

    aws training in omr

    python training in chennai

    python training in omr

    selenium training in chennai

    selenium training in omr

    ReplyDelete
    Replies
      Reply
  14. Jayalakshmi6 August 2020 at 09:15

    3. I have been a keen follower of your website.
    recently I came across this topic and after reading the whole article I am amazed that how well you have written it.
    Amazing writing skills shown.
    hadoop training in chennai

    hadoop training in tambaram

    salesforce training in chennai

    salesforce training in tambaram

    c and c plus plus course in chennai

    c and c plus plus course in tambaram

    machine learning training in chennai

    machine learning training in tambaram

    ReplyDelete
    Replies
      Reply
  15. jeni14 August 2020 at 07:18

    Thanks for any other wonderful post. Where else may just anyone get that type of info in such a perfect means of writing? I’ve a presentation next week, and I am on the look for such information.

    angular js training in chennai

    angular js training in velachery

    full stack training in chennai

    full stack training in velachery

    php training in chennai

    php training in velachery

    photoshop training in chennai

    photoshop training in velachery

    ReplyDelete
    Replies
      Reply
  16. shiny15 August 2020 at 22:24

    Nice information, valuable and excellent design, as share good stuff with good ideas and concepts.



    hadoop training in chennai

    hadoop training in annanagar

    salesforce training in chennai

    salesforce training in annanagar

    c and c plus plus course in chennai

    c and c plus plus course in annanagar

    machine learning training in chennai

    machine learning training in annanagar

    ReplyDelete
    Replies
      Reply
  17. ganesh23 October 2020 at 02:16

    Really very nice blog information for this one and more technical skills are improve, i like that kind of post.
    Angular js Training in Chenai

    Angular js Training in Velachery

    Angular js Training in Tambaram

    Angular js Training in Porur

    Angular js Training in Omr
    Angular js Training in Annanagar

    ReplyDelete
    Replies
      Reply
  18. harini24 October 2020 at 09:09

    Thanks for the Article. Really a great one. Very informative and useful!! Appreciate your time and effort for posting this. Grateful

    Selenium Training in Chennai
    Selenium Training in Velachery
    Selenium Training in Tambaram
    Selenium Training in Porur
    Selenium Training in Omr Selenium Training in Annanagar

    ReplyDelete
    Replies
      Reply
  19. Hemachandran4 November 2020 at 05:36

    Wonderful blog with great piece of information.
    Java course in chennai

    python course in chennai

    web designing and development course in chennai

    selenium course in chennai

    digital-marketing seo course in chennai



    ReplyDelete
    Replies
      Reply
  20. sahasrit4 November 2020 at 23:02

    Well Said, you have furnished the right information that will be useful to anyone at all time. amazon web services aws training in chennai

    microsoft azure course in chennai

    workday course in chennai

    android course in chennai

    ios course in chennai

    ReplyDelete
    Replies
      Reply
  21. Pushba8 November 2020 at 04:54

    you have selected such a nice topic and well explained
    IELTS Coaching in chennai

    German Classes in Chennai

    GRE Coaching Classes in Chennai

    TOEFL Coaching in Chennai

    Spoken english classes in chennai | Communication training

    ReplyDelete
    Replies
      Reply
  22. Prwatech1 January 2021 at 11:49

    I genuinely appreciated understanding it. Sitting tight for some more incredible articles like this from you in the nearing days.

    Hadoop Training Institute in Pune
    Hadoop Administration training institutes in Pune

    ReplyDelete
    Replies
      Reply
  23. Technogeekscs3 June 2021 at 10:39

    This is most informative and also this post most user-friendly and super navigation to all posts.

    DevOps Training Institute in Pune

    ReplyDelete
    Replies
      Reply
  24. SixD Engineering Solutions Pvt Ltd23 October 2021 at 11:14

    I am really happy with your blog because your article is very unique and powerful for new.
    3D Scanning Services Near Me
    3D Scanning Reverse Engineering
    Reverse Engineering Services
    Plant Engineering Services
    Offshore Engineering Services India

    ReplyDelete
    Replies
      Reply
  25. evoseedbox5 February 2022 at 01:43

    WEB DesigningServices in Dehradun
    I explore your all post and found some great information which is definitely useful for me in the future.
    herefor all students on here we have an all assignment service to help you guys to complete their assignment.

    ReplyDelete
    Replies
      Reply
  26. Let2know20 June 2022 at 07:23

    you have executed an uproarious undertaking upon this text. Its completely change and very subjective. you have even figured out how to make it discernible and simple to make a get accord of into. you have a couple of definite composing dexterity. much appreciated likewise a lot. Activation Key For Movavi

    ReplyDelete
    Replies
      Reply
  27. Beel SEO EXPORT21 June 2022 at 20:07

    I go to your blog every now and again and counsel it to the total of people who wanted to highlight on happening their comprehension resulting to ease. The way of composing is perfect and in addition to the substance material is highest point score. gratitude for that insight you give the perusers! Stellar Data Recovery Software With Crack

    ReplyDelete
    Replies
      Reply
  28. Anonymous22 July 2022 at 22:31

    Happy birthday to my incredible, great, stunning and super-attractive sister! If I am told to choose another sister. Happy Birthday Wishes For Sister

    ReplyDelete
    Replies
      Reply
  29. Leesa John9 August 2022 at 07:16

    This comment has been removed by the author.

    ReplyDelete
    Replies
      Reply
  30. Gokul Krish12 May 2026 at 06:49

    Really appreciate the note on scope: {} creating an isolate scope and preventing accidental data leaks between directives. That kind of encapsulation thinking is also crucial when working with large datasets and writing clean analysis code. For developers in Electronic City wanting to pivot into data roles, I’ve been researching data analytics with python training electronic city because Python is great for both back-end logic and data processing. Has anyone here moved from AngularJS development to a data engineering role? What helped the most?

    ReplyDelete
    Replies
      Reply
  31. Anonymous7 June 2026 at 05:17

    Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to
    improve my knowledge as updated one, keep blogging.

    Microsoft Azure Devops Course in Electronic city bangalore
    Data Analytics Training in Electronic City
    AI Training in Electronic City

    ReplyDelete
    Replies
      Reply
  32. lokesh10 June 2026 at 02:19


    Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging
    Best AI Course with Placement Assistance in Electronic City Bangalore
    Data science Training in Electronic City

    ReplyDelete
    Replies
      Reply
  33. lokesh13 June 2026 at 03:58

    This comment has been removed by the author.

    ReplyDelete
    Replies
      Reply
  34. lokesh13 June 2026 at 03:59

    Very informative article! Students searching for an Automation Testing Course with Placement in Electronic City Bangalore will find useful guidance about training and career support.

    ReplyDelete
    Replies
      Reply
  35. lokesh14 June 2026 at 04:31

    The role of an Azure Solutions Architect is becoming increasingly important. Azure Solutions Architect Training in Electronic City Bangalore can be a great way to gain the technical and practical skills companies are looking for.

    ReplyDelete
    Replies
      Reply
  36. lokesh16 June 2026 at 03:58

    6.If you're looking for a Spring Boot institute near me in Electronic City, this training program offers excellent mentorship and project-based learning.

    ReplyDelete
    Replies
      Reply
  37. lokesh17 June 2026 at 04:18

    The explanation of identity management and network security and compliance really made it clear why AZ-500 Training is so valuable. This article is a resource for people who want to be Azure Security Engineers. It explains things in a way that's easy to understand which is really helpful for people who are interested, in AZ-500 Training and want to learn more about it.

    ReplyDelete
    Replies
      Reply
  38. Richu5 July 2026 at 04:00

    Very insightful post! The details about AZ-500 Certification Course electronic city are super helpful for anyone planning to build a career, in Azure cloud security with AZ-500 Certification.

    ReplyDelete
    Replies
      Reply
  39. eMexoT9 July 2026 at 04:48

    I really like this article because it is easy to understand. The person who wrote this article did a job of explaining things in a simple way. I am looking for the Best Power BI Course in Electronic City It is nice to see people making content to help others learn about business intelligence and Power BI. When people work on projects and use real examples they feel more confident about what they are doing with Power BI. I think the Power BI course in Electronic City should have hands-on projects and real world examples. The Power BI course is very useful. I am glad I found this article, about Power BI.

    ReplyDelete
    Replies
      Reply
  40. Anonymous9 November 2026 at 03:02

    I really appreciate the clarity of this article. Every section is easy to follow and understand.ba online training

    ReplyDelete
    Replies
      Reply
  41. prasanth13 November 2026 at 04:46

    Tableau Training in Mumbai helps learners develop practical skills in data visualization, data analytics, dashboard creation, calculated fields, data blending, filters, charts, and interactive reporting. With industry-focused training and hands-on exercises, participants gain experience connecting multiple data sources, analyzing complex datasets, creating interactive dashboards, and presenting meaningful business insights using Tableau. The course is suitable for students and working professionals looking to strengthen their data analytics expertise, develop job-ready skills, and advance their careers in Mumbai's business intelligence and analytics industry.
    Tableau Training in Mumbai

    ReplyDelete
    Replies
      Reply
Add comment
Load more...

Newer Post Older Post Home
Subscribe to: Post Comments (Atom)

Blog Archive

  • ► 2015 (1)
    • ► August (1)
  • ▼ 2014 (4)
    • ▼ April (1)
      • ServiceStack.Redis and StructureMap
    • ► March (1)
    • ► January (2)
  • ► 2013 (18)
    • ► November (2)
    • ► October (2)
    • ► August (2)
    • ► July (1)
    • ► June (2)
    • ► May (1)
    • ► April (2)
    • ► March (2)
    • ► February (2)
    • ► January (2)
  • ► 2012 (12)
    • ► December (2)
    • ► November (3)
    • ► October (2)
    • ► September (1)
    • ► August (2)
    • ► July (2)

Twitter

Follow @NickBlair

Stack Overflow

profile for Nick at Stack Overflow, Q&A for professional and enthusiast programmers

Labels

  • 405 (1)
  • aaa (1)
  • actionfilter (1)
  • agile (2)
  • angularjs (1)
  • apicontroller (1)
  • app settings (3)
  • appharbor (2)
  • architecture (3)
  • areas (1)
  • asp.net (1)
  • automocking (2)
  • availability (1)
  • background workers (1)
  • bdd (4)
  • big ball of mud (1)
  • branching (1)
  • bundling (1)
  • Chef (1)
  • clickonce (1)
  • config transforms (4)
  • continuous delivery (2)
  • continuous deployment (3)
  • continuous integration (2)
  • cookie (2)
  • crud (1)
  • dashing (1)
  • ddd (5)
  • delete (1)
  • dependency injection (2)
  • devops (4)
  • document database (1)
  • dry (1)
  • entity framework (1)
  • environments (2)
  • etag (1)
  • f# (3)
  • fluentassertions (1)
  • four nines (1)
  • functional (2)
  • funscript (1)
  • git (2)
  • github (1)
  • heroku (2)
  • http method (1)
  • httpclient (1)
  • httprequestmessage (1)
  • idempotent (1)
  • iis7 (1)
  • ioc (2)
  • javascript (1)
  • jqueryui (1)
  • kanban (1)
  • linq (1)
  • log4net (1)
  • logentries (1)
  • logging (1)
  • mergetool (1)
  • mfakes (1)
  • mocking (2)
  • moq (2)
  • mspec (1)
  • mvc (1)
  • mvc4 (4)
  • nosql (1)
  • not allowed (1)
  • notes (3)
  • nunit (1)
  • opinion (4)
  • optimise (1)
  • orm (1)
  • polyglot (1)
  • powershell (2)
  • put (1)
  • python (1)
  • ravendb (2)
  • redis (1)
  • resharper (1)
  • rest (1)
  • risk (1)
  • ruby (1)
  • scaling (1)
  • sharding (1)
  • specflow (1)
  • sql (2)
  • state (1)
  • structuremap (3)
  • tdd (6)
  • teamcity (4)
  • type providers (1)
  • ubuntu (1)
  • unit test (2)
  • uptime (1)
  • user story (2)
  • vagrant (2)
  • versioning (2)
  • virtual machine (1)
  • wcf (1)
  • webapi (3)
  • webdeploy (2)
  • websockets (1)
  • Windows 2012 (1)
  • WinRM (1)
  • yagni (1)

Get at Me

Twitter

Linked In

GitHub

Stack Overflow
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.