how to extend InitializeService

2 posts, 0 answers
  1. Bruno
    Bruno avatar
    3 posts
    Member since:
    Feb 2015

    Posted 16 Apr 2015 Link to this post

    Hi,

    I have a question about the generated method InitializeService.

    I understand the concept of extending a service with partial classes, but is there a way to extend the InitializeService?

    I ask this question because of the following scenario:

    suppose you have generated the service:

     

    Namespace SofiaCarRentalDataService
    <System.ServiceModel.ServiceBehavior(IncludeExceptionDetailInFaults := True)>
    Public Class SofiaCarRentalService
            Inherits OpenAccessDataService(Of SofiaCarRentalEntityDiagrams)
    Public Shared Sub InitializeService(ByVal config As DataServiceConfiguration)
                config.UseVerboseErrors = True
                config.SetEntitySetAccessRule("*", EntitySetRights.All)
                config.SetServiceOperationAccessRule("GetRentalOrdersForCar", ServiceOperationRights.AllRead)
                config.SetServiceOperationAccessRule("GetProfitForCar", ServiceOperationRights.AllRead)
                config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3
    End Sub

    Protected Overrides Sub HandleException(ByVal args As HandleExceptionArgs)
    MyBase.HandleException(args)
    End Sub

    End Sub
    End Class

     

     

    the problem with this is that the lines:

                config.SetServiceOperationAccessRule("GetRentalOrdersForCar", ServiceOperationRights.AllRead)
                config.SetServiceOperationAccessRule("GetProfitForCar", ServiceOperationRights.AllRead)

     have to be re-added again and again each time you regenerate the service. Is there a way to extend the InitializeService method in a seperate file?

  2. Viktor Zhivkov
    Admin
    Viktor Zhivkov avatar
    291 posts

    Posted 21 Apr 2015 Link to this post

    Hello Bruno,

    There is no convenient way to customize the InitializeService method body via code.
    Fortunately in your scenario it should be fairly easy to just uncheck both Entity types in the step 3 of the Add Service wizard. This will instruct our code generation to skip any uncheck Entity types so no changes will be required in the code.
    Another option that you have is to skip overwriting the already generated file. This scenario is useful if you have added some custom code there that you want to keep.

    Regards,
    Viktor Zhivkov
    Telerik
     
    OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
     
  3. DevCraft banner
Back to Top