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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T18:05:43+00:00 2026-05-10T18:05:43+00:00

This question is related to a previous post of mine Here . Basically, I

  • 0

This question is related to a previous post of mine Here. Basically, I want to inject a DAO into an entity i.e.

public class User {    IUserDAO userDAO;    public User()    {          userDAO = IoCContainer.Resolve<IUserDAO>;    }   public User(IUserDAO userDAO)    {          this.userDAO = userDAO;    }    //Wrapped DAO methods i.e    public User Save()    {        return userDAO.Save(this);    }  } 

Here if I had a custom methods in my DAO then I basically have to wrap them in the entity object. So if I had a IUserDAO.Register() I would then have to create a User.Register() method to wrap it.

What would be better is to create a proxy object where the methods from the DAO are dynamically assign to the User object. So I may have something that looks like this:

var User = DAOProxyService.Create(new User()); User.Save(); 

This would mean that I can keep the User entity as a pretty dumb class suitable for data transfer over the wire, but also magically give it a bunch of DAO methods.

This is very much out of my confort zone though, and I wondered what I would need to accomplish this? Could I use Castles Dynamic proxy? Also would the C# compiler be able to cope with this and know about the dynamically added methods?

Feel free to let me know if this is nonsense.

EDIT:

What we need to do it somehow declare DAOProxyService.Create() as returning a User object — at compile time. This can be done with generics.

This isnt quite true, what I want to return isn’t a User object but a User object with dynamically added UserDAO methods. As this class isn’t defnied anywhere the compiler will not know what to make of it.

What I am essentially returning is a new object that looks like: User : IUserDAO, so I guess I could cast as required. But this seems messy.

Looks like what I am looking for is similar to this: Mixins

  • 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-10T18:05:44+00:00Added an answer on May 10, 2026 at 6:05 pm

    I was initially going to say what you ask cannot work. But with some tweaking, we might be able to get it to work.

    var is just a compiler feature. When you say.

     var x = GetSomeValue(); 

    the compiler says ”GetSomeValue’ is defined as returning a string, so the programmer must of meant to write ‘string x = GetSomeValue();”. Note that the compiler says this; this change is done at compile time.

    You want to define a class (DAOProxyService) which essentially returns an Object. This will work, but ‘var User’ would be the same as ‘Object user’.

    What we need to do it somehow declare DAOProxyService.Create() as returning a User object — at compile time. This can be done with generics:

    class DAOProxyService {      static DAOProxyService<T> Create<T>(T obj) { ......}  } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question is related to the previous post. How to save file and read
This question is related to a previous post . Is there something comparable to
This question is related with one of my earlier questions.. Previous Post In there
This question is in continuation to my previous post located here . Since there
This question is directly related to my previous question ASP.NET AJAX Is it possible
This is kind of related to my previous question, but not really. I have
Ok, so - this is heavily related to my previous question Transforming an object
This question is related to the question posted here: Why isn't my custom WCF
Thanks to Insin for answering a previous question related to this one. His answer
This question is mostly related to my previous question. I'm having an Edit view

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.