Well, you are using Cocktail in a console application. Cocktail doesn't come with a bootstrapper that correctly composes a console app, so you are most likely missing many pieces trying to shoehorn Cocktail into a console application.
In this particular case the EntityManager isn't getting the AuthenticationContext assigned, because the hook is missing somewhere. In a Silverlight or WPF application, which are the only two platforms officially supported by Cocktail, the FrameworkBootstrapper makes sure that every EntityManager gets the AuthenticationContext assigned.
Modifying the Configure method like follows may get you a little further:
private void Configure() { IAuthenticationService authenticationService = IoC.Get<IAuthenticationService>();
EntityManager.EntityManagerCreated += (sender, args) => args.EntityManager.AuthenticationContext = authenticationService.AuthenticationContext;
if (authenticationService != null) { string userName = ConfigurationManager.AppSettings["username"]; string password = ConfigurationManager.AppSettings["password"]; myLoginCredential loginCredential = new myLoginCredential(userName, password);
authenticationService.Login(loginCredential); //here it logs and the AuthenticationContext is ok } }
|