Particular / NServiceBus

Build, version, and monitor better microservices with the most powerful service platform for .NET
https://particular.net/nservicebus/
Other
2.07k stars 647 forks source link

Not trivial to implement IWantCustomInitialization when used in host process #2179

Closed yvesgoeleven closed 10 years ago

yvesgoeleven commented 10 years ago

The default implementation for configure.With uses private fields to initialize itself, https://github.com/Particular/NServiceBus/blob/develop/src/NServiceBus.Hosting.Windows/GenericHost.cs#L128, but if you have to implement IWantCustomInitialization as a user (which is likely as you have to do it now to set endpointname or conventions as well) you cannot access these and you're on your own to figure out what it should be.

yvesgoeleven commented 10 years ago

it's not even non trivial to do this, it's impossible: FileVersionRetriever is internal

yvesgoeleven commented 10 years ago

Here's what the endpoint config would look like, if FileVersionRetriever weren't internal, for one of the endpoints in the videostore sample:

 public class EndpointConfig : IConfigureThisEndpoint, AsA_Publisher, UsingTransport, IWantCustomInitialization {
        public Configure Init()
        {
            var assemblyScanner = new AssemblyScanner();
            assemblyScanner.MustReferenceAtLeastOneAssembly.Add(typeof(IHandleMessages<>).Assembly);
            var assembliesToScan = assemblyScanner
                .GetScannableAssemblies()
                .Assemblies;
            var endpointName = this.GetType().Namespace ?? this.GetType().Assembly.GetName().Name;
            var endpointVersionToUse = FileVersionRetriever.GetFileVersion(this.GetType());
            var config = Configure.With(o =>
            {
                o.EndpointName(endpointName );
                o.EndpointVersion(() => endpointVersionToUse);
                o.AssembliesToScan(assembliesToScan);
                o.Conventions(c =>
                        c.DefiningCommandsAs(t => t.Namespace != null && t.Namespace.StartsWith("VideoStore") && t.Namespace.EndsWith("Commands"))
                         .DefiningEventsAs(t =>t.Namespace != null && t.Namespace.StartsWith("VideoStore") && t.Namespace.EndsWith("Events"))
                         .DefiningMessagesAs(t =>t.Namespace != null && t.Namespace.StartsWith("VideoStore") &&t.Namespace.EndsWith("RequestResponse"))
                         .DefiningEncryptedPropertiesAs(p => p.Name.StartsWith("Encrypted")));
            });
            return config;
        }
    }
johnsimons commented 10 years ago

@yvesgoeleven why do u need FileVersionRetriever ?

yvesgoeleven commented 10 years ago

I don't know, but I just want to be able to start off with the same settings as the defaults

andreasohlund commented 10 years ago

Talked this through with @johnsimons today we need to fix this.

On Tue, Jun 17, 2014 at 11:24 AM, Yves Goeleven notifications@github.com wrote:

I don't know, but I just want to be able to start off with the same settings as the defaults

— Reply to this email directly or view it on GitHub https://github.com/Particular/NServiceBus/issues/2179#issuecomment-46285243 .

andreasohlund commented 10 years ago

@johnsimons did you talk to @SimonCropp ?

andreasohlund commented 10 years ago

done

SimonCropp commented 10 years ago

@andreasohlund "done"?? was there a commit for this? what was the resolution?

johnsimons commented 10 years ago

This was fixed as part of the refactoring done to the configuration story, but this was also raised as part of testing the first cut of the v5 API so it doesn't really belong to the v5 milestone