Im developing a desktop application in WPF that relies on a webservice to log in and get license information. This means that the user logs in and i build a client side (in my desktop application) object with the licensing and the login date etc.
Im using StructureMap and want to pass my IMyUser implementation into my ViewModels constructor (constructor DI). My question is this, where should i put my initialization of my structure map if im to pass my IMyUser implementation into the constructor?
Im thinking after i login and have created the IMyUserObject i can configure StructureMap and pass it the instance of my user object. This would be somewhat “late” in my application (normally i put it in my app class, so its run as the first thing within my application).
If this is not the proper way to utilize the IMyUser and DI please advice, also alternative solitions would be greatly appreciated.
As this is a question about authorization I think it would be much better handled by a custom IPrincipal implementation.
When the application starts up, assign an implementation to Thread.CurrentPrincipal. This initial instance should not authorize the user.
When the user has logged in and received the license information, replace or update Thread.CurrentPrincipal to authorize the user to use the application.
This is an example of the Ambient Context pattern. You don’t need to involve StructureMap in this interaction.