[...]
public class ProfileProvider : Profile, IProfileProvider {
public Profile GetProfile() {
return Create(HttpContext.Current.Profile.UserName) as Profile;
} // GetProfile
public Profile GetProfile(String username) {
return Create(username) as Profile;
} // GetProfile
}
ProfileProvider, as the ULR I provided, it will have a reference in
the Web.Config.
Looks sort of weird to me. Just looking at the class "Profile", is it
your intent that the class be able to return (for example) the "name" via
the property as well as via the class indexer?
If that's by design, then maybe that's okay. But ProfileProvider looks
especially odd. If I've got a ProfileProvider, which inherits Profile,
why wouldn't I just use the ProfileProvider when I want a Profile? What
is it about ProfileProvider that makes it a Profile, _and_ also something
that returns Profile instances?
Note that this is not _necessarily_ a problem. For example, in
hierarchical data structures, you might see something like this. Such as
in the System.Xml.Linq namespace, where an XElement is an XNode, and can
also return an XNode related to it (or many, for that matter).
But if there's a relationship like that in your data structure, it's not
readily apparent from your description. And if there's not a relationship
like that in your data structure, then the data structure doesn't look
quite right to me.
Pete
I am not entirely sure I am doing this right but I am thinking as
follows:
I have the following projects on my solution:
1. MyProject.Core that includes:
- The models (Profile, Post, ...)
- The Profile interface and repositories interfaces
2. MyProject.SqlMembershipProvider (uses ASP.NET Membership)
- Includes the AccountRepository
The AccountRepository uses Account Model.
The account model has many properties, including Profile
2. MyProject.SqlDataProvider
- Includes all repositories that deal with SQL database
3. MyProject.Mvc
- The MVC application
I want to separate Profile Model from the Profile Provider because
later I might use another Membership provider.
For example, my own SQL tables including it in SQLDataProvider or a
XML Provider.
But the profile model and interfaces will be the same. Only the
Provider code will change.
Does this make any sense??
Now, about the Profile class I followed the link I mentioned but I
also found the following Link in MSDN:
http://msdn.microsoft.com/en-us/library/system.web.profile.profilebase.aspx
That contains the code, on the bottom, of a custom profile provider:
using System;
using System.Web.Profile;
namespace Samples.AspNet.Profile
{
public class EmployeeProfile : ProfileBase
{
[SettingsAllowAnonymous(false)]
[ProfileProvider("EmployeeInfoProvider")]
public string Department
{
get { return base["EmployeeDepartment"].ToString(); }
set { base["EmployeeDepartment"] = value; }
}
[SettingsAllowAnonymous(false)]
[ProfileProvider("EmployeeInfoProvider")]
public EmployeeInfo Details
{
get { return (EmployeeInfo)base["EmployeeInfo"]; }
set { base["EmployeeInfo"] = value; }
}
}
public class EmployeeInfo
{
public string Name;
public string Address;
public string Phone;
public string EmergencyContactName;
public string EmergencyContactAddress;
public string EmergencyContactPhone;
}
}
The only thing that is added to this code, as far as I can see, is the
two methods GetProfile to make it easier to get the current user
profile or a another user profile.
Anyway, what do you think?
I am not sure I am planning this right but as far as I understand I
can't find any problem.
Thank You,
Miguel