Quantcast
Channel: Caliburn.Micro: Xaml Made Easy
Viewing all articles
Browse latest Browse all 1760

New Post: WinRTContainer after RegisterPerRequest/RegisterSingleton crashes on object retrieval

$
0
0

how are you trying to retrieve?

By using RegisterHandler you circumventing some of the code buildups, same with RegisterSingleton.  I suspect it has something to do with the constructor.  I actually ran a test...

drop the " : this(null) " and you might be surprised...

the compiler even throws you a bone when you forget to include the 1 constructor with a parameter when you have

StorageDataAccess () : this(null)

It then expects a parametered constructor to exist and I am guess the compiler does a check (constructor signatures all match) and then once buildup occurs in the container it goes ape cause it doesn't have the parameter with the declaration in the RegisterXX method that it actually needs to match up to your object in this case a StorageFolder

 

///<summary>///   Registers the instance.///</summary>///<param name = "service">The service.</param>///<param name = "key">The key.</param>///<param name = "implementation">The implementation.</param>publicvoid RegisterInstance(Type service, string key, object implementation)
        {
            RegisterHandler(service, key, container => implementation);
        }///<summary>///   Registers the class so that a new instance is created on every request.///</summary>///<param name = "service">The service.</param>///<param name = "key">The key.</param>///<param name = "implementation">The implementation.</param>publicvoid RegisterPerRequest(Type service, string key, Type implementation)
        {
            RegisterHandler(service, key, container => container.BuildInstance(implementation));
        }///<summary>///   Registers the class so that it is created once, on first request, and the same instance is returned to all requestors thereafter.///</summary>///<param name = "service">The service.</param>///<param name = "key">The key.</param>///<param name = "implementation">The implementation.</param>publicvoid RegisterSingleton(Type service, string key, Type implementation)
        {object singleton = null;
            RegisterHandler(service, key, container => singleton ?? (singleton = container.BuildInstance(implementation)));
        }///<summary>///   Registers a custom handler for serving requests from the container.///</summary>///<param name = "service">The service.</param>///<param name = "key">The key.</param>///<param name = "handler">The handler.</param>publicvoid RegisterHandler(Type service, string key, Func<SimpleContainer, object> handler)
        {
            GetOrCreateEntry(service, key).Add(handler);
        }

those are the signatures for the different Register methods, slight differences but each has its purpose.  Then you have to look how BuildInstance does its thing to get to a working instance/singleton of the object


Viewing all articles
Browse latest Browse all 1760

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>