コード例 #1
0
        /// <summary>
        /// Registers <see cref="JsonConnectionFactory"/> that relies on
        /// <see cref="IMessageTypeCache"/>. <see cref="Serialization.RegistrationExtensions.AddSerializationCore(IServiceCollection)"/>
        /// should be called first.
        /// </summary>
        public static MessageTypeCacheBuilder AddJson(this MessageTypeCacheBuilder builder)
        {
            builder.Services.AddTransient <IJsonConnectionFactory, JsonConnectionFactory>();
            builder.AddMessageType(typeof(JsonSerializedMessage));

            return(builder);
        }
コード例 #2
0
    /// <summary>
    /// Scans the assembly for types marked with <see cref="MessageAttribute"/>
    /// attribute and adds them to the cache builder.
    /// </summary>
    /// <param name="builder">Cache builder where to add message types.</param>
    /// <param name="assembly">Assembly to scan for message types.</param>
    public static MessageTypeCacheBuilder AddMessageTypesFromAssembly(
        this MessageTypeCacheBuilder builder, Assembly assembly)
    {
        foreach (var type in assembly.GetTypes().Where(t => t.GetCustomAttribute <MessageAttribute>() != null))
        {
            builder.AddMessageType(type);
        }

        return(builder);
    }