[CAB] Création d'un ContextBoundController
Je suis en plein développement d'un CAB project et j'ai besoin que mes controllers hérite de ContextBoundObject pour me créé un proxie qui va valider mes PrincipalPermissionAttribute de mes méthodes et demander les permission via le CREDUI et impersonalisé l'action.
Mais voila que le CAB n'aime pas trop trop la class ContextBound, jai cette exception
Citation:
Cannot create uninitialized instances of types requiring managed activation.
Voila comment mes class fonctionne
J'ai mon SmartPart
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
[SmartPart]
public partial class SubSystemsList : UserControl
{
public SubSystemsList()
{
InitializeComponent();
}
private SubSystemsController _controller;
[CreateNew]
public SubSystemsController Controller
{
private get { return _controller; }
set { _controller = value; }
}
private void ShowSubSystems()
{
List<Common.ISubSystem> subSystems = Controller.GetSubSystems();
foreach (Common.ISubSystem item in subSystems)
{
SubSytemsPanel.Controls.Add(new SubSystem(item));
}
}
private void SubSystemsList_Load(object sender, EventArgs e)
{
if (DesignMode) return;
ShowSubSystems();
}
} |
Le controller est créé par injection [CreateNew]
J'ai mon Controller
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
public class SubSystemsController : Common.ContextBoundController
{
public SubSystemsController()
{
}
private Shell.Common.Services.ISubSystemsService _subSystemsService;
[ServiceDependency]
public Shell.Common.Services.ISubSystemsService SubSystemsService
{
get { return _subSystemsService; }
set { _subSystemsService = value; }
}
private SubSystemsWorkItem _workItem;
[ServiceDependency]
public SubSystemsWorkItem WorkItem
{
get { return _workItem; }
set { _workItem = value; }
}
public List<ISubSystem> GetSubSystems()
{
return SubSystemsService.GetSubSystems();
}
public void RunSubSystem(ISubSystem subSystem)
{
WorkItem.LeaveLobby();
// Show subsystem in workspace...
subSystem.Show(WorkItem.Workspaces[Common.Workspaces.Window]);
}
} |
Mon ContextBoundController
Code:
1 2 3 4 5 6 7 8 9
|
[InterceptCall]
public class ContextBoundController: ContextBoundObject
{
public ContextBoundController(): base()
{
}
} |
Mon InterceptCall context
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
[AttributeUsage(AttributeTargets.Class)]
public class InterceptCallAttribute : ContextAttribute
{
public InterceptCallAttribute(): base("InterceptCall")
{
}
public override void GetPropertiesForNewContext(System.Runtime.Remoting.Activation.IConstructionCallMessage ctorMsg)
{
ctorMsg.ContextProperties.Add(new InterceptContextProperty());
}
}
public class InterceptContextProperty : IContextProperty, IContributeObjectSink
{
#region IContextProperty Members
public void Freeze(Context newContext)
{
}
public bool IsNewContextOK(Context newCtx)
{
return true;
}
public string Name
{
get { return "InterceptCall"; }
}
#endregion
#region IContributeObjectSink Members
public System.Runtime.Remoting.Messaging.IMessageSink GetObjectSink(MarshalByRefObject obj, System.Runtime.Remoting.Messaging.IMessageSink nextSink)
{
return new InterceptSink(nextSink);
}
#endregion
}
public class InterceptSink: IMessageSink
{
public InterceptSink(IMessageSink nextSink)
{
_nextSink = nextSink;
}
#region IMessageSink Members
public IMessageCtrl AsyncProcessMessage(IMessage msg, IMessageSink replySink)
{
return NextSink.AsyncProcessMessage(msg, replySink);
}
private readonly IMessageSink _nextSink;
public IMessageSink NextSink
{
get
{
return _nextSink;
}
}
public IMessage SyncProcessMessage(IMessage msg)
{
return NextSink.SyncProcessMessage(msg);
}
#endregion
} |
Voila, le probleme se retrouve au niveau de cette injection
Code:
1 2 3 4 5 6 7 8
|
private SubSystemsController _controller;
[CreateNew]
public SubSystemsController Controller
{
private get { return _controller; }
set { _controller = value; }
} |
Je doit absolument passé par un CreateNew, sinon l'injection dans le SubSystemsController ne se fait pas.
La ligne du CAB qui throw l'exception est celle-ci
Code:
1 2
|
existing = FormatterServices.GetSafeUninitializedObject(typeToBuild); |
Qqn a déja utiliser du ContextBound avec le CAB ?