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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T04:20:24+00:00 2026-05-30T04:20:24+00:00

I am working on a C# based application in which I have a utility

  • 0

I am working on a C# based application in which I have a utility interface with an internal back end that creates some objects and registers them internally in the application.
So the code looks like the following:

public interface Utility {
     public SomeObject CreateSomeObject(String id);
}

Only the Utility interface is visible outside my assembly, the concrete back end class is internal.
I am really stuck on finding a proper name for the creation methods which should tell the user that the wanted object will be created and registered.
Any suggestions?

EDIT I already thought about naming my methods CreateAndRegisterSomeObject() but some objects have really long names which makes some method names very very long

Thanks in advance,

  • 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-30T04:20:25+00:00Added an answer on May 30, 2026 at 4:20 am

    I don’t really like the idea that your method is doing so much ie both create and register, but if it must then I would approach it by using generics most likely.

    public interface IUtility {
        T CreateAndRegister<T>(String id) where T : IIdentifiable, new();
        T CreateAndRegister<T>(ComplexInitInfo somethingElse) where T : ISomethingElseable, new();
    }
    

    This would allow you to cater for multiple classes that have the same construction pattern without putting verbose plumbing code, ie having to create methods containing the name of every single object you need to create and register. Let the generics do the heavy lifting for you.

    Your objects would have to implement some interfaces such as

    public interface IIdentifiable
    {
        string Id { get; set; }
    }
    
    public class ComplexInitInfo
    {
        public int SomeId { get; set; }
        public string SomethingElse { get; set; }
    }
    
    // this is just an example
    public interface ISomethingElseable : IIdentifiable
    {
        string SomethingElse { get; set; }
    }
    

    Then you would could implement your Utility class in something along the following lines:

    public class Utility : IUtility
    {
        public T CreateAndRegister<T>(string id) where T : IIdentifiable, new()
        {
            T result = new T();
            result.Id = id;
    
            // do your registration 
    
            return result;
        }
    
        public T CreateAndRegister<T>(ComplexInitInfo somethingElse) where T : ISomethingElseable, new()
        {
            T result = new T();
            result.Id = somethingElse.SomeId;
            result.SomethingElse = somethingElse.SomethingElse;
    
            // do your registration 
    
            return result;
        }
    }
    

    A different approach

    I would also like to point out the pattern you are trying to use CreateAndRegister is a problem already solved slightly differently with Inversion of Control frameworks (e.g. ninject, unity amongst others)

    They allow you to register and associate a given type to a lifetime that the object has. If you want to register types as singletons for example, the IoC framework can do that for you, then when you Resolve you will get an instance of the type you want respecting the lifetime that it has been configured to. You could want for example, a new instance when every time you resolve the type, or a only a new instance per thread, or to have the same instance always returned when you resolve.

    In any case, good luck!

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

Sidebar

Related Questions

i am working on an application which is based on accelerometer. i have a
currently I am working on a spring based application. I do have some unit
I am working with navigation based application. Every cell creates a detailView. i have
I am a developer working on an internal web-based application, and I have been
Working with the Google Web Toolkit i have written an application which is based
I'm working on a web based application which uses a JSON over HTTP based
I am currently working on an application which requires different behaviour based on whether
I am working on an internal web based application for storing and cataloging photos.
I am working on a basic Struts based application that is experience major spikes
This is driving me nuts. I have a working text based application. It has

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.