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 796203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T22:36:16+00:00 2026-05-14T22:36:16+00:00

At the moment, we’ve got an unmaintanable ball of code which offers an interface

  • 0

At the moment, we’ve got an unmaintanable ball of code which offers an interface to a third party application. The third party application has a COM assembly which MUST be used to create new entries. This process involves two steps: generate a new object (basically an ID), and update that object with new field values.
Because COM interop is so slow, we only use that to generate the ID (and related objects) in the database. The actual update is done using a regular SQL query.

What I am trying to figure out if it’s possible to use NHibernate to do some of the heavy lifting for us, without bypassing the COM assembly. Here’s the code for saving something to the database as I envision it:

using(var s = sessionFactory.OpenSession())
using(var t = s.BeginTransaction())
{
    MyEntity entity = new MyEntity();
    s.Save(entity);
    t.Commit();
}

Regular NH code I’d say. Now, this is where it gets tricky. I think I have to supply my own implementation of NHibernate.Id.IIdentifierGenerator which calls the COM assembly in the Generate method. That’s not a problem. What IS a problem is that the COM assembly requires initialisation, which does take a bit of time. It also doesn’t like multiple instances in the same process, for some reason.
What I would like to know is if there’s a way to properly access an external service in the generator code.

I’m free to use any technique I want, so if it involves something like an IoC container that’s no problem. The thing I am looking for is where exactly to hook-up my code so I can access the things I need in my generator, without having to resort to using singletons or other nasty stuff.

  • 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-14T22:36:17+00:00Added an answer on May 14, 2026 at 10:36 pm

    Assuming you want a single instance of the COM component for all of your entities, a Service Locator (implemented with any IoC container) is the way to go.

    Your (trivial) IIdentifierGenerator implementation would have to call the locator in its constructor to get the component instance, and call the corresponding method on the component on Generate.

    One thing to consider: is the COM component thread-safe? If not, you should synchronize the Generate calls.

    Usage of the generator is simple, just use the fully-qualified name as your generator class.

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

Sidebar

Related Questions

At the moment my code (PHP) has too many SQL queries in it. eg...
The moment I added a unit test to my ASP.NET MVC application to test
At the moment I have about 2000 trades which are priced using excel. I
At the moment my application.js file looks like this: //= require_tree ./vendor //= require_directory
At the moment we are deploying our whole application chain together and at once
At the moment I’m working on a win32 application in Windows. I made a
at the moment I have a small application and need to take information from
At the moment I have an C# console application that exposes Web Services through
At the moment the following code will load only when the users clicks the
At the moment, the Hibernate Validator has released the latest version as 4.3.0.Final here

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.