This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Customer | |
{ | |
public int Id { get; set; } | |
public string Name { get; set; } | |
public string Email { get; set; } | |
public string Phone { get; set; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Address | |
{ | |
public int Id { get; set; } | |
public string Street { get; set; } | |
public string City { get; set; } | |
public string Country { get; set; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select | |
C.[Id], C.[Name], C.[Email], C.[Phone], | |
A.CustomerId, A.Street, A.City, A.Country, A.ZIPCode | |
from customer C inner join [Address] A on A.CustomerId = C.Id |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
List<Customer> ret; | |
using (var db = new SqlConnection(connstring)) | |
{ | |
var sql = | |
"select C.[Id], C.[Name], C.[Email], C.[Phone], A.CustomerId, A.Street, " + | |
"A.City, A.Country, A.ZIPCode from customer C " + | |
"inner join[Address] A on A.CustomerId = C.Id"; | |
ret = db.Query<Customer, Address, Customer>(sql, (customer, address) => | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public ConnectionFactory GetConnectionFactory() | |
{ | |
var connectionFactory = new ConnectionFactory | |
{ | |
HostName = "localhost", | |
UserName = "guest", | |
Password = "guest" | |
}; | |
return connectionFactory; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public IConnection CreateConnection(ConnectionFactory connectionFactory) | |
{ | |
return connectionFactory.CreateConnection(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public QueueDeclareOk CreateQueue(string queueName, IConnection connection) | |
{ | |
QueueDeclareOk queue; | |
using (var channel = connection.CreateModel()) | |
{ | |
queue = channel.QueueDeclare(queueName, false, false, false, null); | |
} | |
return queue; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public bool WriteMessageOnQueue(string message, string queueName, IConnection connection) | |
{ | |
using (var channel = connection.CreateModel()) | |
{ | |
channel.BasicPublish(string.Empty, queueName, null, Encoding.ASCII.GetBytes(message)); | |
} | |
return true; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public string RetrieveSingleMessage(string queueName, IConnection connection) | |
{ | |
BasicGetResult data; | |
using (var channel = connection.CreateModel()) | |
{ | |
data = channel.BasicGet(queueName, true); | |
} | |
return data != null ? System.Text.Encoding.UTF8.GetString(data.Body) : null; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.AspNetCore.Builder; | |
using Microsoft.AspNetCore.Hosting; | |
using Microsoft.Extensions.Configuration; | |
using Microsoft.Extensions.DependencyInjection; | |
namespace SwaggerAspnetCore | |
{ | |
public class Startup | |
{ | |
public Startup(IConfiguration configuration) |
OlderNewer