RegisterInstance - new object per resolve

Mar 22, 2011 at 4:30 PM

I am implementing Ioc and there are few things i want to make sure are right.

1.If I use RegisterInstance, on resolving it will always return the singleton object?
2.BootStrapper will be loaded in Global.asax or some place where it will be loaded initially, which means all the instances will be singleton?
But i want to know how to

1. Create a separate instance per resolve, PerResolve wont work with RegisterInstance, it works only with RegisterType.
2. If I make dependent object as static property, it will work the same way, if i am able to create separate instance per resolve?

please help?

public class ClientUser : UserServiceBase, IClientUser
    private  IDataServiceManager _dataServiceManager;
    public ClientUser()


    private IDataServiceManager DataServiceMgr
            if (_dataServiceManager == null)
                _dataServiceManager = ProjectContainer.Instance.Resolve<IDataServiceManager>();

            return _dataServiceManager;

Mar 24, 2011 at 3:45 AM

Yes, registering using RegisteringInstance will cause a singleton object to be returned when you resolved it from the container. 

I believe there's no built-in lifetime manager which you can use with the RegisterInstance which will produce the behavior you want.   The easiest way would be to register the type using RegisterType and configuring injection for it.

See also Chris Tavares' response to a somewhat similar question logged here.


Sarah Urmeneta
Global Technologies and Solutions
Avanade, Inc.