Hi
In VB.Net you are technically allowed to have a class and a module with the same name (as a module is just the VB.Net equivalent to a C# static class) but as a developer would you be happy with that?
I am using it to allow the static creation of generic classes e.g.:-
With the module thus:-Code:Public NotInheritable Class FileProjectionSnapshotReader(Of TAggregate As CQRSAzure.EventSourcing.IAggregationIdentifier, TAggregationKey, TProjection As IProjection) Inherits FileProjectionSnapshotBase(Of TAggregate, TAggregationKey, TProjection) Implements IProjectionSnapshotReader(Of TAggregate, TAggregationKey, TProjection) Public Function GetSnapshot(key As TAggregationKey, Optional OnOrBeforeSequence As UInteger = 0) As IProjectionSnapshot(Of TAggregate, TAggregationKey) Implements IProjectionSnapshotReader(Of TAggregate, TAggregationKey, TProjection).GetSnapshot Throw New NotImplementedException() End Function Public Function GetLatestSnapshotSequence(key As TAggregationKey, Optional OnOrBeforeSequence As UInteger = 0) As UInteger Implements IProjectionSnapshotReader(Of TAggregate, TAggregationKey, TProjection).GetLatestSnapshotSequence Throw New NotImplementedException() End Function Private Sub New(ByVal AggregateDomainName As String, ByVal AggregateKey As TAggregationKey, Optional ByVal settings As IFileStreamSettings = Nothing) MyBase.New(AggregateDomainName, AggregateKey, writeAccess:=False, connectionStringName:=GetReadConnectionStringName("", settings), settings:=settings) End Sub #Region "Factory methods" ''' <summary> ''' Creates an azure file storage based event stream reader for the given aggregate ''' </summary> ''' <param name="instance"> ''' The instance of the aggregate for which we want to read the event stream ''' </param> ''' <param name="projection"> ''' </param> Public Shared Function Create(ByVal instance As CQRSAzure.EventSourcing.IAggregationIdentifier(Of TAggregationKey), ByVal projection As TProjection, Optional ByVal settings As IFileStreamSettings = Nothing) As IProjectionSnapshotReader(Of TAggregate, TAggregationKey, TProjection) Dim domainName As String = DomainNameAttribute.GetDomainName(instance) If settings IsNot Nothing Then If Not String.IsNullOrWhiteSpace(settings.DomainName) Then domainName = settings.DomainName End If End If Return New FileProjectionSnapshotReader(Of TAggregate, TAggregationKey, TProjection)(domainName, instance.GetKey(), settings) End Function #End Region End Class
Would this be OK in you ropinion, or should I rename the module FileProjectionSnapshotReaderFactory?Code:Public Module FileProjectionSnapshotReader ''' <summary> ''' Creates an azure file storage based event stream reader for the given aggregate ''' </summary> ''' <param name="instance"> ''' The instance of the aggregate for which we want to read the event stream ''' </param> ''' <param name="projection"> ''' </param> Public Function Create(Of TAggregate As CQRSAzure.EventSourcing.IAggregationIdentifier, TAggregationKey, TProjection As IProjection)(ByVal instance As TAggregate, ByVal key As TAggregationKey, ByVal projection As TProjection, Optional ByVal settings As IFileStreamSettings = Nothing) As IProjectionSnapshotReader(Of TAggregate, TAggregationKey, TProjection) Dim domainName As String = DomainNameAttribute.GetDomainName(instance) If settings IsNot Nothing Then If Not String.IsNullOrWhiteSpace(settings.DomainName) Then domainName = settings.DomainName End If End If Return FileProjectionSnapshotReader(Of TAggregate, TAggregationKey, TProjection).Create(instance, projection, settings) End Function End Module




Reply With Quote