<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Alex</title>
    <description>The latest articles on Forem by Alex (@alexgreatdev).</description>
    <link>https://forem.com/alexgreatdev</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F847055%2F2e909ac7-ba1e-4542-a793-7bff09c0445a.jpeg</url>
      <title>Forem: Alex</title>
      <link>https://forem.com/alexgreatdev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/alexgreatdev"/>
    <language>en</language>
    <item>
      <title>Entity Framework Core Add if not exist</title>
      <dc:creator>Alex</dc:creator>
      <pubDate>Tue, 17 May 2022 12:40:41 +0000</pubDate>
      <link>https://forem.com/alexgreatdev/entity-framework-core-add-if-not-exist-507a</link>
      <guid>https://forem.com/alexgreatdev/entity-framework-core-add-if-not-exist-507a</guid>
      <description>&lt;p&gt;Have you tried to check if the entity exists and if not — add it.&lt;/p&gt;

&lt;p&gt;you can use this code&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;using Microsoft.EntityFrameworkCore.ChangeTracking;
public static class DbSetExtensions
{
public static EntityEntry&amp;lt;T&amp;gt; AddIfNotExists&amp;lt;T&amp;gt;(this DbSet&amp;lt;T&amp;gt; dbSet, T entity, Expression&amp;lt;Func&amp;lt;T, bool&amp;gt;&amp;gt; predicate = null) where T : class, new()
{
var exists = predicate != null ? dbSet.Any(predicate) : dbSet.Any();
return !exists ? dbSet.Add(entity) : null;
}
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var purchase = new Models.Purchase();
var trackingnumber= "222";
_context.Purchases.AddIfNotExists(purchase,p=&amp;gt;p.BankTrackingNum== trackingnumber);
await _context.SaveChangesAsync();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;“Read before write” can violate data integrity without being put inside a transaction control.&lt;/p&gt;

&lt;p&gt;In SQL Server, you can use merge statement. However merge statement is not available in EF.&lt;/p&gt;

&lt;p&gt;Happy Coding👨‍💻&lt;/p&gt;

</description>
      <category>netcore</category>
      <category>efcore</category>
      <category>sql</category>
      <category>dotnet</category>
    </item>
    <item>
      <title>MinIO SDK Using REST API .NET For Amazon S3 Storage and MinIO</title>
      <dc:creator>Alex</dc:creator>
      <pubDate>Wed, 13 Apr 2022 22:32:20 +0000</pubDate>
      <link>https://forem.com/alexgreatdev/minio-sdk-using-rest-api-net-for-amazon-s3-storage-and-minio-bd</link>
      <guid>https://forem.com/alexgreatdev/minio-sdk-using-rest-api-net-for-amazon-s3-storage-and-minio-bd</guid>
      <description>&lt;p&gt;MinIO SDK Using REST API .NET For Amazon S3 Storage and MinIO&lt;br&gt;
Object storage defined&lt;br&gt;
Object storage is a data storage architecture for large stores of unstructured data. It designates each piece of data as an object, keeps it in a separate storehouse, and bundles it with metadata and a unique identifier for easy access and retrieval.&lt;br&gt;
MinIO&lt;br&gt;
MinIO offers high-performance, S3 compatible object storage.&lt;br&gt;
Native to Kubernetes, MinIO is the only object storage suite available on&lt;br&gt;
every public cloud, every Kubernetes distribution, the private cloud and the&lt;br&gt;
edge. MinIO is software-defined and is 100% open source under GNU AGPL v3.&lt;br&gt;
We will get started by create new .NET 5 project and Create Api ,then we will get to MinIO SDK, after which we will Create Service Minio and run Get and put command object with it.&lt;br&gt;
Github Project : &lt;a href="https://github.com/AlexGreatDev/AmazonS3"&gt;https://github.com/AlexGreatDev/AmazonS3&lt;/a&gt;&lt;br&gt;
Create new .NET 5 project&lt;br&gt;
Following commands create a new Web API with .NET 5 CLI:&lt;br&gt;
&lt;code&gt;#Create the API&lt;br&gt;
dotnet new webapi -o AmazonS3&lt;br&gt;
cd AmazonS3&lt;/code&gt;&lt;br&gt;
Create a new file ObjectController.cs in the Controllers folder . This will add 2 new requests:&lt;br&gt;
POST request at &lt;code&gt;object/&lt;/code&gt;&lt;br&gt;
GET request at object?objectname=@objectid&amp;amp;bucket=@bucketid&lt;br&gt;
Install MinIO&lt;br&gt;
To install MinIO .NET package, run the following command in Nuget Package Manager Console.&lt;br&gt;
&lt;code&gt;PM&amp;gt; Install-Package Minio&lt;/code&gt;&lt;br&gt;
Create Service Minio&lt;br&gt;
Create class MinioObject.cs in AmazonS3.Services.Minio Folder.&lt;br&gt;
constructor:&lt;br&gt;
&lt;code&gt;private MinioClient _minio;&lt;br&gt;
public MinioObject()&lt;br&gt;
{&lt;br&gt;
_minio = new MinioClient()&lt;br&gt;
.WithEndpoint("Address")&lt;br&gt;
.WithCredentials("YOUR-ACCESSKEYID",&lt;br&gt;
"YOUR-SECRETACCESSKEY")&lt;br&gt;
.WithSSL()//if Domain is SSL&lt;br&gt;
.Build();&lt;br&gt;
}&lt;/code&gt;&lt;br&gt;
Put object :&lt;br&gt;
&lt;code&gt;public async Task&amp;lt;string&amp;gt; PutObj(PutObjectRequest request)&lt;br&gt;
{&lt;br&gt;
var bucketName = request.bucket;&lt;br&gt;
// Check Exists bucket&lt;br&gt;
bool found = await _minio.BucketExistsAsync(new BucketExistsArgs().WithBucket(bucketName));&lt;br&gt;
if (!found)&lt;br&gt;
{&lt;br&gt;
// if bucket not Exists,make bucket&lt;br&gt;
await _minio.MakeBucketAsync(new MakeBucketArgs().WithBucket(bucketName));&lt;br&gt;
}&lt;br&gt;
System.IO.MemoryStream filestream = new System.IO.MemoryStream(request.data);&lt;br&gt;
var filename = Guid.NewGuid();&lt;br&gt;
// upload object&lt;br&gt;
await _minio.PutObjectAsync(new PutObjectArgs()&lt;br&gt;
.WithBucket(bucketName).WithFileName(filename.ToString())&lt;br&gt;
.WithStreamData(filestream).WithObjectSize(filestream.Length)&lt;br&gt;
);&lt;br&gt;
return await Task.FromResult&amp;lt;string&amp;gt;(filename.ToString());&lt;br&gt;
}&lt;br&gt;
Get Object&lt;br&gt;
public async Task&amp;lt;GetObjectReply&amp;gt; GetObject(string bucket, string objectname)&lt;br&gt;
{&lt;br&gt;
MemoryStream destination = new MemoryStream();&lt;br&gt;
// Check Exists object&lt;br&gt;
var objstatreply= await _minio.StatObjectAsync(new StatObjectArgs()&lt;br&gt;
.WithBucket(bucket)&lt;br&gt;
.WithObject(objectname)&lt;br&gt;
);&lt;br&gt;
if (objstatreply == null || objstatreply.DeleteMarker)&lt;br&gt;
throw new Exception(“object not found or Deleted”);&lt;br&gt;
// Get object&lt;br&gt;
await _minio.GetObjectAsync(new GetObjectArgs()&lt;br&gt;
.WithBucket(bucket)&lt;br&gt;
.WithObject(objectname)&lt;br&gt;
.WithCallbackStream((stream) =&amp;gt;&lt;br&gt;
{&lt;br&gt;
stream.CopyTo(destination);&lt;br&gt;
}&lt;br&gt;
)&lt;br&gt;
);&lt;br&gt;
return await Task.FromResult&amp;lt;GetObjectReply&amp;gt;(new GetObjectReply()&lt;br&gt;
{&lt;br&gt;
data = destination.ToArray(),&lt;br&gt;
objectstat = objstatreply&lt;br&gt;
});&lt;br&gt;
}&lt;/code&gt;&lt;br&gt;
Models :&lt;br&gt;
&lt;code&gt;using Minio.DataModel;&lt;br&gt;
namespace AmazonS3.Services.Minio.Model&lt;br&gt;
{&lt;br&gt;
public class GetObjectReply&lt;br&gt;
{&lt;br&gt;
public ObjectStat objectstat { get; set; }&lt;br&gt;
public byte[] data { get; set; }&lt;br&gt;
}&lt;br&gt;
}&lt;/code&gt;&lt;br&gt;
And&lt;br&gt;
&lt;code&gt;namespace AmazonS3.Services.Minio.Model&lt;br&gt;
{&lt;br&gt;
public class PutObjectRequest&lt;br&gt;
{&lt;br&gt;
public string bucket { get; set; }&lt;br&gt;
public byte[] data { get; set; }&lt;br&gt;
}&lt;br&gt;
}&lt;/code&gt;&lt;br&gt;
Then add Call Minio Service in ObjectController.cs&lt;br&gt;
&lt;code&gt;private readonly ILogger&amp;lt;ObjectController&amp;gt; _logger;&lt;br&gt;
private readonly MinioObject _minio;&lt;br&gt;
public ObjectController(ILogger&amp;lt;ObjectController&amp;gt; logger, MinioObject minio)&lt;br&gt;
{&lt;br&gt;
_logger = logger;&lt;br&gt;
_minio = minio;&lt;br&gt;
}&lt;br&gt;
[HttpGet]&lt;br&gt;
public async Task&amp;lt;ActionResult&amp;gt; Get(string objectname, UploadTypeList bucket)&lt;br&gt;
{&lt;br&gt;
var result = await _minio.GetObject(bucket.ToString(), objectname);&lt;br&gt;
return File(result.data, result.objectstat.ContentType);&lt;br&gt;
}&lt;br&gt;
[HttpPost]&lt;br&gt;
public async Task&amp;lt;ActionResult&amp;gt; Post(UploadRequest request)&lt;br&gt;
{&lt;br&gt;
var result = await _minio.PutObj(new Services.Minio.Model.PutObjectRequest()&lt;br&gt;
{&lt;br&gt;
bucket = request.type.ToString(),&lt;br&gt;
data = request.data&lt;br&gt;
});&lt;br&gt;
return Ok(new { filename = result });&lt;br&gt;
}&lt;br&gt;
and Add Minio service in IOC for DI in Startup:&lt;br&gt;
public void ConfigureServices(IServiceCollection services)&lt;br&gt;
{&lt;br&gt;
services.AddControllers();&lt;br&gt;
services.AddScoped&amp;lt;MinioObject&amp;gt;();&lt;br&gt;
}&lt;/code&gt;&lt;br&gt;
Summary&lt;br&gt;
Keep in mind that the Service is only available for .NET 5 or Higher. If you would like to use it in .NET Core, you have to use AmazonS3_NetCore Solution.&lt;br&gt;
Here is the repo from the project, I hope you liked it. Happy coding!&lt;/p&gt;

</description>
      <category>dotnet</category>
      <category>objectstorage</category>
      <category>amazons3</category>
      <category>restapi</category>
    </item>
    <item>
      <title>Object Storage</title>
      <dc:creator>Alex</dc:creator>
      <pubDate>Wed, 13 Apr 2022 22:27:29 +0000</pubDate>
      <link>https://forem.com/alexgreatdev/object-storage-5656</link>
      <guid>https://forem.com/alexgreatdev/object-storage-5656</guid>
      <description>&lt;p&gt;Object storage defined&lt;br&gt;
Object storage is a data storage architecture for large stores of unstructured data. It designates each piece of data as an object, keeps it in a separate storehouse, and bundles it with metadata and a unique identifier for easy access and retrieval.&lt;br&gt;
Object storage vs. file storage vs. block storage&lt;br&gt;
Object storage takes each piece of data and designates it as an object. Data is kept in separate storehouses versus files in folders and is bundled with associated metadata and a unique identifier to form a storage pool.&lt;br&gt;
File storage stores data as a single piece of information in a folder to help organize it among other data. This is also called hierarchical storage, imitating the way that paper files are stored. When you need access to data, your computer system needs to know the path to find it.&lt;br&gt;
Block Storage takes a file apart into singular blocks of data and then stores these blocks as separate pieces of data. Each piece of data has a different address, so they don’t need to be stored in a file structure.&lt;br&gt;
Benefits of object storage&lt;br&gt;
Now that we’ve described what object storage is, what are its benefits?&lt;br&gt;
Greater data analytics. Object storage is driven by metadata, and with this level of classification for every piece of data, the opportunity for analysis is far greater.&lt;br&gt;
Infinite scalability. Keep adding data, forever. There’s no limit.&lt;br&gt;
Faster data retrieval. Due to the categorization structure of object storage, and the lack of folder hierarchy, you can retrieve your data much faster.&lt;br&gt;
Reduction in cost. Due to the scale-out nature of object storage, it’s less costly to store all your data.&lt;br&gt;
Optimization of resources. Because object storage does not have a filing hierarchy, and the metadata is completely customizable, there are far fewer limitations than with file or block storage.&lt;br&gt;
Object storage use cases&lt;br&gt;
There are multiple use cases for object storage. For example, it can assist you in the following ways:&lt;br&gt;
Deliver rich media. Define workflows by leveraging industry-leading solutions for managing unstructured data. Reduce your costs for globally distributed rich media.&lt;br&gt;
Manage distributed content. Optimize the value of your data throughout its lifecycle and deliver competitive storage services.&lt;br&gt;
Embrace the Internet of Things (IoT). Manage machine-to-machine data efficiently, support artificial intelligence and analytics, and compress the cost and time of the design process.&lt;br&gt;
What is Amazon S3 Storage?&lt;br&gt;
Amazon Simple Storage Service (S3) is a storage system for the internet, where you can store and retrieve any amount of data, anytime, anywhere. This make web-scaling computing easier for developers, and it also gives them access to the infrastructure that Amazon uses to conduct a global network of websites. The Amazon S3 API offers a common path for rapid development and the creation of hybrid cloud deployments at scale.&lt;/p&gt;




&lt;p&gt;References:&lt;br&gt;
&lt;a href="https://cloud.google.com/learn/what-is-object-storage"&gt;https://cloud.google.com/learn/what-is-object-storage&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.netapp.com/data-storage/storagegrid/what-is-object-storage/"&gt;https://www.netapp.com/data-storage/storagegrid/what-is-object-storage/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>object</category>
      <category>storage</category>
      <category>amazon</category>
      <category>minio</category>
    </item>
    <item>
      <title>Implementing Domain-Driven Design</title>
      <dc:creator>Alex</dc:creator>
      <pubDate>Wed, 13 Apr 2022 22:25:45 +0000</pubDate>
      <link>https://forem.com/alexgreatdev/implementing-domain-driven-design-1dkp</link>
      <guid>https://forem.com/alexgreatdev/implementing-domain-driven-design-1dkp</guid>
      <description>&lt;p&gt;“With Implementing Domain-Driven Design, Vaughn has made an important contribution not only to the literature of the Domain-Driven Design community, but also to the literature of the broader enterprise application architecture field. In key chapters on Architecture and Repositories, for example, Vaughn shows how DDD fits with the expanding array of architecture styles and persistence technologies for enterprise applications — including SOA and REST, NoSQL and data grids — that has emerged in the decade since Eric Evans’ seminal book was first published. And, fittingly, Vaughn illuminates the blocking and tackling of DDD — the implementation of entities, value objects, aggregates, services, events, factories, and repositories — with plentiful examples and valuable insights drawn from decades of practical experience. In a word, I would describe this book as thorough. For software developers of all experience levels looking to improve their results, and design and implement domain-driven enterprise applications consistently with the best current state of professional practice, Implementing Domain-Driven Design will impart a treasure trove of knowledge hard won within the DDD and enterprise application architecture communities over the last couple decades.”&lt;br&gt;
— Randy Stafford, Architect At-Large, Oracle Coherence Product Development&lt;br&gt;
Most developers have had to change the way they think in order to properly apply DDD. We developers are technical thinkers. Technical solutions come easy for us. It’s not that thinking technically is bad. It’s just that there are times when thinking less technically is better. If it’s been our habit to practice software development only in technical ways for years, perhaps now would be a good time to consider a new way of thinking. Developing the Ubiquitous Language of your domain is the best place to start.&lt;br&gt;
Cowboy Logic&lt;br&gt;
LB: “That fella’s boots are too small. If he don’t find himself another pair, his toes are gonna hurt.”&lt;br&gt;
AJ: “Yep. If you don’t listen, you’re gonna have to feel.”&lt;br&gt;
How to Involve Domain Experts in Your Project&lt;br&gt;
Coffee. Use that Ubiquitous Language:&lt;br&gt;
“Hi, Sally, I got you a tall half-skinny half-one-percent extra-hot split-quad-shot latte with whip. Do you have a few minutes to talk about . . . ?”&lt;br&gt;
Learn to use the Ubiquitous Language of C-Level management: “. . . profits . . . revenues . . . competitive edge . . . market domination.” Seriously.&lt;br&gt;
Hockey tickets&lt;br&gt;
There’s another level of thought that is required with DDD that goes beyond concept naming. When we model a domain through software, we are required to give careful thought to which model objects do what. It’s about designing the behaviors of objects. Yes, we want the behaviors to be named properly to convey the essence of the Ubiquitous Language. But what an object does by means of a specific behavior must be considered. This is a level of effort that goes beyond creating attributes on a class and exposing getters and setters publicly to clients of the model.&lt;br&gt;
So, I hope you enjoyed it. Happy Coding👨‍💻&lt;/p&gt;




&lt;p&gt;References&lt;br&gt;
[Vaughn Vernon],“Implementing Domain-Driven Design”&lt;/p&gt;

</description>
      <category>ddd</category>
      <category>domain</category>
      <category>analyst</category>
      <category>object</category>
    </item>
  </channel>
</rss>
