views:

22

answers:

0

I have used the Silverlight BusinessApplication template in VS2010. I have changed the AuthenticationService to use my own Authentication methods - the requirement is that the user logs into the system with their SQL login (no AD in the company).

On login, I construct a SQLConnection, attempt to open it, then I get their details (friendly name, roles etc) from a User table. I then store the username and password that they entered and any time they hit the DB through a DomainService I override CreateObjectContext and insert the username and password they entered into the DB.

I have changed the AuthenticationService to inherit from IAuthentication and LinqToEntitiesDomainService, mainly for accessing the User table.

I'm running into an issue when starting the application, before the user has logged in. The LoginStatus control that comes with the BusinessApplication template has the following line:

private readonly AuthenticationService authService = WebContext.Current.Authentication;

This causes the constructor of my AuthenticationService to be called and, as part of that, the ObjectContext is attempted to be created but the user has not yet logged in so I have no username + password to add into the connection string. For dev. purposes I just use my username and password if not logged in but I'm now required to fix this.

Any ideas on how I can get round this? My options as far as I can see are:

  • Don't use EF (I would rather use it as the rest of my data access is done using EF).
  • Create a dummy user in the DB and use this as the credentials if not logged in (not ideal).

Is there another way round this? On construction of my AuthenticationService prevent CreateObjectContext being called?

Any help/suggestions appreciated.

Update

I changed my AuthenticationService to inherit from DomainService rather than LinqToEntitiesDomainService and used a SqlDataReader to get the User data that was required but I'm stil curious as to whether there is another way.