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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T15:24:32+00:00 2026-05-11T15:24:32+00:00

I recently created an interface layer to distinguish the DataAccessProvider from our Business logic

  • 0

I recently created an interface layer to distinguish the DataAccessProvider from our Business logic layer. With this approach we can change our choice of DataAccessProvider whenever we want by changing the values in the Web/App.Config. (more details can be given if needed).

Anyway, to do this we use reflection to accomplish our DataProvider class on which we can work.

/// <summary> /// The constructor will create a new provider with the use of reflection. /// If the assembly could not be loaded an AssemblyNotFoundException will be thrown. /// </summary> public DataAccessProviderFactory() {     string providerName = ConfigurationManager.AppSettings['DataProvider'];     string providerFactoryName = ConfigurationManager.AppSettings['DataProviderFactory'];     try     {         activeProvider = Assembly.Load(providerName);         activeDataProviderFactory = (IDataProviderFactory)activeProvider.CreateInstance(providerFactoryName);     }     catch     {         throw new AssemblyNotFoundException();     } } 

But now I’m wondering how slow reflection is?

  • 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. 2026-05-11T15:24:33+00:00Added an answer on May 11, 2026 at 3:24 pm

    In most cases: more than fast enough. For example, if you are using this to create a DAL wrapper object, the time taken to create the object via reflection will be minuscule compared to the time it needs to connect to a network. So optimising this would be a waste of time.

    If you are using reflection in a tight loop, there are tricks to improve it:

    • generics (using a wrapper where T : new() and MakeGenericType)
    • Delegate.CreateDelegate (to a typed delegate; doesn’t work for constructors)
    • Reflection.Emit – hardcore
    • Expression (like Delegate.CreateDelegate, but more flexible, and works for constructors)

    But for your purposes, CreateInstance is perfectly fine. Stick with that, and keep things simple.


    Edit: while the point about relative performance remains, and while the most important thing, ‘measure it’, remains, I should clarify some of the above. Sometimes… it does matter. Measure first. However, if you find it is too slow, you might want to look at something like FastMember, which does all the Reflection.Emit code quietly in the background, to give you a nice easy API; for example:

    var accessor = TypeAccessor.Create(type); List<object> results = new List<object>(); foreach(var row in rows) {     object obj = accessor.CreateNew();     foreach(var col in cols) {         accessor[obj, col.Name] = col.Value;     }     results.Add(obj); } 

    which is simple, but will be very fast. In the specific example I mention about a DAL wrapper—if you are doing this lots, consider something like dapper, which again does all the Reflection.Emit code in the background to give you the fastest possible but easy to use API:

    int id = 12345; var orders = connection.Query<Order>(     'select top 10 * from Orders where CustomerId = @id order by Id desc',     new { id }).ToList(); 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've recently asked a question regarding best ways of separating business logic from data
I recently created a turn-based game server that can accept 10s of thousands of
I've recently created these two (unrelated) methods to replace lots of boiler-plate code in
I'm a pretty new C# and .NET developer. I recently created an MMC snapin
I started a Rails project recently and decided to use RESTful controllers. I created
I recently came across this in some code - basically someone trying to create
Recently, I started changing some of our applications to support MS SQL Server as
Recently our site has been deluged with the resurgence of the Asprox botnet SQL
Recently I've read, and implemented 80% of examples from Pro ASP.NET MVC Framework ,
I recently created a class which has a constructor taking 3 enumerations as arguments.

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.