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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T12:20:14+00:00 2026-05-19T12:20:14+00:00

I have what I think is a fairly common problem, but I cannot seem

  • 0

I have what I think is a fairly common problem, but I cannot seem to find a good way to solve it.

Let’s say I have an interface IFoo and I use Unity to create an instance of Foo:

class Foo : IFoo {}
IFoo foo = Container.Resolve<IFoo>();

After initialization I would like to to call a method for post-processing FooPostProc that takes in a Foo object (not IFoo interface)
For example I would like

return Container.Resolve<IFoo>();

to be equivalent to:

void FooPostProc(Foo obj){}
Foo obj = new Foo();
FooPostProc(obj) ;
return obj ;

Essentially I would like to specify in the Unity container configuration (xml preferably) a method to call on the specific instance of the object immediately after the object is created. I am doing this as I am not able to add additional constructors to the original Foo object.

I am seeing some hints that it may be possible using Unity Interception, but it looks very involved. Is there a reasonably simple way this can be accomplished using Unity configuration ?

  • 1 1 Answer
  • 4 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-19T12:20:15+00:00Added an answer on May 19, 2026 at 12:20 pm

    There’s two options here.

    If you’re not otherwise using it, Method injection will work – you can configure methods to call on the instance as it’s created. There’s no guarantee of ordering between methods if you’re using multiple injection methods, but it works. This only works if the post processing method is a method of the object you’ve created.

    Via the API, you do:

    container.RegisterType<IFoo, Foo>(
      // ... constructor, property configuration
      new InjectionMethod("FooPostProc"));
    

    or in XML:

    <register type="IFoo" mapTo="Foo">
      <method name="FooPostProc" />
    </register>
    

    You can also pass parameters to the method just like you can to the constructor.

    The other option is to use the undocumented, but included, BuilderAwareStrategy. You’ll need to write a small Unity extension to add the strategy to the container.

    Once you do, you can then implement Microsoft.Practices.ObjectBuilder2.IBuilderAware interface. At the end of the resolve process, the container will call IBuilderAware.OnBuiltUp. Again, this requires you implement the method on the type that’s being resolved.

    For example:

    public class myClass : IBuilderAware
    {
    .. regular class implementation..
    public void OnBuiltUp(NamedTypeBuildKey buildkey) {}
    public void OnTearingDown() {}
    }
    

    If the post-processing method isn’t on the object being resolved, the quickest thing would be to use an InjectionFactory (API only, no XML) and do whatever you want.

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

Sidebar

Related Questions

I have a problem at hand which I'd think is fairly common amongst groups
Here's my situation, and it's probably fairly common but I have yet to find
I have what I think should be a fairly simple mapping issue, but not
I think I have a solution to this, but is there a better way,
I think I have a problem in understanding the proper way of using MVC.
I have what I think should be a fairly simple implementation, but I'm running
I think this is probably a fairly common but I haven't found a match
Screen is amazing, of course, but I don't want to have to think about
I think I have a synchronization problem...It may be too basic..Please help.. I have
I think I have a basic understanding of REST, but something I'm stuck on

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.