Skip to main content
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Notice removed Draw attention by CommunityBot
Bounty Ended with no winning answer by CommunityBot
Notice added Draw attention by Mathematics
Bounty Started worth 50 reputation by Mathematics
added 20 characters in body; edited title
Source Link
Jamal
  • 34.9k
  • 13
  • 133
  • 237

Can this single WCF data service class be improved as it is doing a lot

I have this WCF data service class, and I believe it is doing a lot,:

I thinkI'm thinking moving out Query & ChangeQuery and Change interceptors out of this class but not sure if this will be a good move neither. I also don't know if it is possible, but abovethe code is working as it is, so any improvement would help.

Can this single service class be improved as it is doing a lot

I have this WCF data service class, I believe it is doing a lot,

I think moving out Query & Change interceptors out of this class but not sure if this will be a good move neither know if it is possible but above code is working as it is, any improvement would help.

WCF data service class

I have this WCF data service class and I believe it is doing a lot:

I'm thinking moving out Query and Change interceptors out of this class but not sure if this will be a good move. I also don't know if it is possible, but the code is working as it is, so any improvement would help.

Source Link
Mathematics
  • 934
  • 2
  • 8
  • 27

Can this single service class be improved as it is doing a lot

I have this WCF data service class, I believe it is doing a lot,

[System.ServiceModel.ServiceBehavior(IncludeExceptionDetailInFaults = true)]
public class PetSuppliesRelationalData : EntityFrameworkDataService<PetSuppliesEntities>
{       
    private string _TenantID
    {
        get
        {
            return HttpContext.Current.User.Identity.Name;
        }
    }

    public static void InitializeService(DataServiceConfiguration config)
    {
        config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3;
        config.UseVerboseErrors = true;
        
        config.SetEntitySetAccessRule("*", EntitySetRights.AllRead);

        config.SetEntitySetAccessRule("Categories", EntitySetRights.All);
        config.SetEntitySetAccessRule("Products", EntitySetRights.All);

        config.SetEntitySetAccessRule("RealErrors", EntitySetRights.None);
        config.SetEntitySetAccessRule("OtherDiagrams", EntitySetRights.None);
        config.SetEntitySetAccessRule("Favourites", EntitySetRights.None);
        config.SetEntitySetAccessRule("Auditing", EntitySetRights.None);

        config.SetEntitySetAccessRule("Compaines", EntitySetRights.None);
        
        config.SetServiceOperationAccessRule("*", ServiceOperationRights.All);
    }

    protected override void OnStartProcessingRequest(ProcessRequestArgs args)
    {
        base.OnStartProcessingRequest(args);
        ThrowIfNotAuthenticated();
    }

    protected override void HandleException(HandleExceptionArgs args)
    {
        LoggingFramework.LogError("Exception ", args.Exception);
        base.HandleException(args);
    }

    private static void ThrowIfNotAuthenticated()
    {
        var identity = HttpContext.Current.User.Identity;
        if (identity == null || !identity.IsAuthenticated)
        {
            throw new Exception("Not Authenticated");
        }
    }
    
    
    #region Query Intercepters
    
    [QueryInterceptor("Table1")]
    public Expression<Func<Table1, Boolean>> OnQueryTable1()
    {
        return x => x.TenantID == _TenantID;
    }
    
    // one for each table in db
    
    #endregion

    #region Change Interceptors
    
    [ChangeInterceptor("Table1")]
    public void OnChangeTable1(Table1 data1, UpdateOperations operations)
    {
        // check if user is authorized etc..
        switch (operations)
        {
            case UpdateOperations.Add:
                break;
            case UpdateOperations.Change:
                break;
            case UpdateOperations.Delete:
                break;
            case UpdateOperations.None:
                break;
        }
    }

    // one for each table in db
    
    #endregion
}   

I think moving out Query & Change interceptors out of this class but not sure if this will be a good move neither know if it is possible but above code is working as it is, any improvement would help.