Print Page | Close Window

Get to imported objects inside server-side methods

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=3478
Printed Date: 23-Jan-2026 at 1:52pm


Topic: Get to imported objects inside server-side methods
Posted By: katit
Subject: Get to imported objects inside server-side methods
Date Posted: 04-Jun-2012 at 8:15pm
I'm trying to implement some server-side methods but not sure how to get to MEF Composition container
 
public class ServerMethods
    {
        [Import]
        public IPushNotificator PushNotificator { get; set; }
        [AllowRpc]   
        public static void PushToDevices(IPrincipal principal, EntityManager entityManager, params object[] args)
        {         
            return;
        }
    }
 
I need to access my PushNotificator from PushToDevices methods. Server-side method is static and I don't get PushNotificator. How do I access this object in my scenario?



Replies:
Posted By: sbelini
Date Posted: 08-Jun-2012 at 12:40pm
Hi katit,
In this case you might want to try access it within the method itself:
 
  [AllowRpc]
  public static void PushToDevices(IPrincipal principal, EntityManager entityManager, params object[] args) {
    var pushNotificator = IdeaBlade.Core.Composition.CompositionHost.Instance.GetExportedInstance<IPushNotificator>(false);
  }
 
The cause of the issue might be that because ServerMethods is never instantiated, there isn't an instance of it to be referenced by the static method.
 
Regards,
   Silvio.


Posted By: katit
Date Posted: 08-Jun-2012 at 12:52pm
Yes, sure it's not in Static. Actually, it's not in  IdeaBlade.Core.Composition.CompositionHost either.
 
I got it from my own Bootstrapper class..



Print Page | Close Window