mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-12-08 15:24:07 +00:00
Merge pull request #362 from gnh1201/dev
Edit README.md (Catswords.Phantomizer)
This commit is contained in:
commit
386c7ca7a1
|
|
@ -3,6 +3,8 @@
|
||||||
**Catswords.Phantomizer** is an HTTP-based dynamic-link library (DLL) loader designed for .NET applications.
|
**Catswords.Phantomizer** is an HTTP-based dynamic-link library (DLL) loader designed for .NET applications.
|
||||||
It allows your application to fetch and load assemblies directly from your CDN (Azure Blob, S3, Cloudflare R2, etc.) at runtime, with optional GZip compression support.
|
It allows your application to fetch and load assemblies directly from your CDN (Azure Blob, S3, Cloudflare R2, etc.) at runtime, with optional GZip compression support.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 🚀 Features
|
## 🚀 Features
|
||||||
|
|
@ -20,7 +22,13 @@ It allows your application to fetch and load assemblies directly from your CDN (
|
||||||
|
|
||||||
### 1. Embed Phantomizer into your project
|
### 1. Embed Phantomizer into your project
|
||||||
|
|
||||||
Add `Catswords.Phantomizer.dll.gz` to your `Resources.resx` file.
|
You can include **Catswords.Phantomizer** in your project using one of the following methods:
|
||||||
|
|
||||||
|
| Method | Description | When to Use | Setup Steps |
|
||||||
|
|-------|-------------|--------------|-------------|
|
||||||
|
| **Resources.resx Embedded File** | Stores `Catswords.Phantomizer.dll.gz` inside `Resources.resx` and loads it at runtime. | Recommended when you want the loader fully self-contained inside your executable. | Add file to `Resources.resx` → Access via `Properties.Resources.Phantomizer`. |
|
||||||
|
| **Embedded Resource** | Embeds `Catswords.Phantomizer.dll.gz` directly into the assembly manifest (outside of `resx`). | Useful when you prefer not to maintain `.resx` files but still want Phantomizer embedded. | Add file to project → Set *Build Action* = `Embedded Resource` → Load via `GetManifestResourceStream()`. |
|
||||||
|
| **Normal Assembly Reference (no embedding)** | References `Catswords.Phantomizer.dll` normally through project references. | Use this when you distribute Phantomizer as a standalone DLL instead of embedding it. | Add Phantomizer DLL to your project references → `using Catswords.Phantomizer;`. |
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
@ -30,13 +38,20 @@ Place the following code inside your `Main` method, static constructor, or any e
|
||||||
|
|
||||||
```csharp
|
```csharp
|
||||||
static Program() {
|
static Program() {
|
||||||
// ...
|
|
||||||
InitializeAssemblyLoader();
|
InitializeAssemblyLoader();
|
||||||
// ...
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void InitializeAssemblyLoader()
|
private static void InitializeAssemblyLoader()
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
|
// Example for Embedded Resource:
|
||||||
|
var asm = Assembly.GetExecutingAssembly();
|
||||||
|
using (var stream = asm.GetManifestResourceStream(typeof(Program).Namespace + ".Resources.Catswords.Phantomizer.dll.gz"))
|
||||||
|
{
|
||||||
|
// decompress and load...
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
byte[] gzBytes = Properties.Resources.Phantomizer;
|
byte[] gzBytes = Properties.Resources.Phantomizer;
|
||||||
|
|
||||||
byte[] dllBytes;
|
byte[] dllBytes;
|
||||||
|
|
@ -51,9 +66,9 @@ private static void InitializeAssemblyLoader()
|
||||||
Assembly phantomAsm = Assembly.Load(dllBytes);
|
Assembly phantomAsm = Assembly.Load(dllBytes);
|
||||||
Type loaderType = phantomAsm.GetType("Catswords.Phantomizer.AssemblyLoader", true);
|
Type loaderType = phantomAsm.GetType("Catswords.Phantomizer.AssemblyLoader", true);
|
||||||
|
|
||||||
loaderType.GetProperty("BaseUrl")?.SetValue(null, GetAppConfig("AssemblyBaseUrl")); // Set your CDN base URL
|
loaderType.GetProperty("BaseUrl")?.SetValue(null, GetAppConfig("AssemblyBaseUrl")); // Set the CDN base URL
|
||||||
loaderType.GetProperty("LoaderNamespace")?.SetValue(null, typeof(Program).Namespace);
|
loaderType.GetProperty("LoaderNamespace")?.SetValue(null, typeof(Program).Namespace);
|
||||||
loaderType.GetProperty("AppName")?.SetValue(null, "WelsonJS"); // Set your application name
|
loaderType.GetProperty("AppName")?.SetValue(null, "WelsonJS"); // Application name
|
||||||
loaderType.GetMethod("Register")?.Invoke(null, null);
|
loaderType.GetMethod("Register")?.Invoke(null, null);
|
||||||
|
|
||||||
var loadNativeModulesMethod = loaderType.GetMethod(
|
var loadNativeModulesMethod = loaderType.GetMethod(
|
||||||
|
|
@ -76,6 +91,26 @@ private static void InitializeAssemblyLoader()
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
If embedding is not required, you can reference Phantomizer directly:
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
using Catswords.Phantomizer;
|
||||||
|
|
||||||
|
static void Main(string[] args)
|
||||||
|
{
|
||||||
|
AssemblyLoader.BaseUrl = GetAppConfig("AssemblyBaseUrl"); // Configure CDN base URL
|
||||||
|
AssemblyLoader.LoaderNamespace = typeof(Program).Namespace;
|
||||||
|
AssemblyLoader.AppName = "WelsonJS";
|
||||||
|
AssemblyLoader.Register();
|
||||||
|
|
||||||
|
AssemblyLoader.LoadNativeModules(
|
||||||
|
"ChakraCore",
|
||||||
|
new Version(1, 13, 0, 0),
|
||||||
|
new[] { "ChakraCore.dll" }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
### 3. Upload your DLL files to a CDN
|
### 3. Upload your DLL files to a CDN
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user