|
| 1 | +--- |
| 2 | +layout: default |
| 3 | +title: Ray.Di Complete Tutorial |
| 4 | +permalink: /tutorial/ |
| 5 | +--- |
| 6 | + |
| 7 | +# Ray.Di Complete Tutorial: Building a Real-World E-commerce Platform |
| 8 | + |
| 9 | +Welcome to the comprehensive Ray.Di tutorial! This tutorial will guide you through building a real-world e-commerce platform while learning all aspects of dependency injection, design patterns, and aspect-oriented programming with Ray.Di. |
| 10 | + |
| 11 | +## 🎯 What You'll Learn |
| 12 | + |
| 13 | +- **Dependency Injection Principles**: Understanding DI, IoC, and SOLID principles |
| 14 | +- **Ray.Di Fundamentals**: All binding types, scopes, and advanced features |
| 15 | +- **Real-World Application**: Building a complete e-commerce platform |
| 16 | +- **Design Patterns**: Factory, Strategy, Observer, and more with DI |
| 17 | +- **Aspect-Oriented Programming**: Cross-cutting concerns and interceptors |
| 18 | +- **Testing Strategies**: Unit testing, mocking, and integration testing |
| 19 | +- **Best Practices**: Performance, troubleshooting, and maintainable code |
| 20 | + |
| 21 | +## 📋 Tutorial Structure |
| 22 | + |
| 23 | +Each section is designed to be independent - you can start anywhere based on your needs! |
| 24 | + |
| 25 | +### 🔰 Part 1: Foundations |
| 26 | +- [Dependency Injection Principles](01-foundations/dependency-injection-principles.md) |
| 27 | +- [SOLID Principles in Practice](01-foundations/solid-principles.md) |
| 28 | +- [Ray.Di Fundamentals](01-foundations/raydi-fundamentals.md) |
| 29 | + |
| 30 | +### 🏗️ Part 2: Basic Bindings |
| 31 | +- [Instance Bindings](02-basic-bindings/instance-bindings.md) |
| 32 | +- [Class Bindings](02-basic-bindings/class-bindings.md) |
| 33 | +- [Provider Bindings](02-basic-bindings/provider-bindings.md) |
| 34 | + |
| 35 | +### 🚀 Part 3: Advanced Bindings |
| 36 | +- [Conditional Bindings](03-advanced-bindings/conditional-bindings.md) |
| 37 | +- [Multibindings](03-advanced-bindings/multibindings.md) |
| 38 | +- [Assisted Injection](03-advanced-bindings/assisted-injection.md) |
| 39 | + |
| 40 | +### ♻️ Part 4: Scopes & Lifecycle |
| 41 | +- [Singleton Scope](04-scopes-lifecycle/singleton-scope.md) |
| 42 | +- [Request Scope](04-scopes-lifecycle/request-scope.md) |
| 43 | +- [Custom Scopes](04-scopes-lifecycle/custom-scopes.md) |
| 44 | + |
| 45 | +### 🎭 Part 5: AOP & Interceptors |
| 46 | +- [Aspect-Oriented Programming](05-aop-interceptors/aspect-oriented-programming.md) |
| 47 | +- [Method Interceptors](05-aop-interceptors/method-interceptors.md) |
| 48 | +- [Common Cross-cutting Concerns](05-aop-interceptors/common-crosscutting-concerns.md) |
| 49 | + |
| 50 | +### 🛒 Part 6: Real-World Examples |
| 51 | +- [Web Application Architecture](06-real-world-examples/web-application/) |
| 52 | +- [Data Access Layer](06-real-world-examples/data-access/) |
| 53 | +- [Authentication & Authorization](06-real-world-examples/authentication/) |
| 54 | +- [Logging & Audit System](06-real-world-examples/logging-audit/) |
| 55 | + |
| 56 | +### 🧪 Part 7: Testing Strategies |
| 57 | +- [Unit Testing with DI](07-testing-strategies/unit-testing-with-di.md) |
| 58 | +- [Mocking Dependencies](07-testing-strategies/mocking-dependencies.md) |
| 59 | +- [Integration Testing](07-testing-strategies/integration-testing.md) |
| 60 | + |
| 61 | +### 💎 Part 8: Best Practices |
| 62 | +- [Design Patterns with DI](08-best-practices/design-patterns.md) |
| 63 | +- [Performance Considerations](08-best-practices/performance-considerations.md) |
| 64 | +- [Troubleshooting Guide](08-best-practices/troubleshooting.md) |
| 65 | + |
| 66 | +## 🛒 Case Study: E-commerce Platform |
| 67 | + |
| 68 | +Throughout this tutorial, we'll build **"ShopSmart"** - a complete e-commerce platform featuring: |
| 69 | + |
| 70 | +- **User Management**: Registration, authentication, profiles |
| 71 | +- **Product Catalog**: Categories, inventory, search |
| 72 | +- **Order Processing**: Cart, checkout, payment |
| 73 | +- **Administration**: Analytics, reporting, management |
| 74 | +- **Infrastructure**: Caching, logging, monitoring |
| 75 | + |
| 76 | +This real-world example demonstrates how Ray.Di enables: |
| 77 | +- **Modularity**: Clean separation of concerns |
| 78 | +- **Testability**: Easy unit and integration testing |
| 79 | +- **Maintainability**: Loose coupling and high cohesion |
| 80 | +- **Scalability**: Proper scope management and performance |
| 81 | +- **Extensibility**: Plugin architecture and interceptors |
| 82 | + |
| 83 | +## 🎓 Learning Paths |
| 84 | + |
| 85 | +### For Beginners |
| 86 | +1. Start with [Dependency Injection Principles](01-foundations/dependency-injection-principles.md) |
| 87 | +2. Learn [Ray.Di Fundamentals](01-foundations/raydi-fundamentals.md) |
| 88 | +3. Practice with [Basic Bindings](02-basic-bindings/) |
| 89 | +4. Explore [Real-World Examples](06-real-world-examples/) |
| 90 | + |
| 91 | +### For Experienced Developers |
| 92 | +1. Jump to [Advanced Bindings](03-advanced-bindings/) |
| 93 | +2. Master [AOP & Interceptors](05-aop-interceptors/) |
| 94 | +3. Study [Design Patterns](08-best-practices/design-patterns.md) |
| 95 | +4. Review [Best Practices](08-best-practices/) |
| 96 | + |
| 97 | +### For Architects |
| 98 | +1. Focus on [SOLID Principles](01-foundations/solid-principles.md) |
| 99 | +2. Study [Scopes & Lifecycle](04-scopes-lifecycle/) |
| 100 | +3. Examine [Web Application Architecture](06-real-world-examples/web-application/) |
| 101 | +4. Review [Performance Considerations](08-best-practices/performance-considerations.md) |
| 102 | + |
| 103 | +## 🔧 Prerequisites |
| 104 | + |
| 105 | +- PHP 8.1+ |
| 106 | +- Composer |
| 107 | +- Basic understanding of OOP concepts |
| 108 | +- Familiarity with interfaces and abstract classes |
| 109 | + |
| 110 | +## 🚀 Quick Start |
| 111 | + |
| 112 | +```bash |
| 113 | +# Clone the tutorial examples |
| 114 | +git clone https://github.com/ray-di/tutorial-examples.git |
| 115 | +cd tutorial-examples |
| 116 | + |
| 117 | +# Install dependencies |
| 118 | +composer install |
| 119 | + |
| 120 | +# Run the first example |
| 121 | +php examples/01-basics/hello-world.php |
| 122 | +``` |
| 123 | + |
| 124 | +## 📖 Code Examples |
| 125 | + |
| 126 | +All examples are: |
| 127 | +- **Runnable**: Complete, working code |
| 128 | +- **Progressive**: Building complexity step by step |
| 129 | +- **Practical**: Based on real-world scenarios |
| 130 | +- **Well-documented**: Extensive comments and explanations |
| 131 | + |
| 132 | +## 🎯 Key Concepts Covered |
| 133 | + |
| 134 | +### Dependency Injection Patterns |
| 135 | +- Constructor Injection |
| 136 | +- Method Injection |
| 137 | +- Property Injection |
| 138 | +- Interface Segregation |
| 139 | + |
| 140 | +### Design Principles |
| 141 | +- **Single Responsibility**: One reason to change |
| 142 | +- **Open/Closed**: Open for extension, closed for modification |
| 143 | +- **Liskov Substitution**: Derived classes must be substitutable |
| 144 | +- **Interface Segregation**: No forced dependencies on unused interfaces |
| 145 | +- **Dependency Inversion**: Depend on abstractions, not concretions |
| 146 | + |
| 147 | +### Ray.Di Features |
| 148 | +- **Binding DSL**: Fluent configuration API |
| 149 | +- **Scopes**: Singleton, prototype, request, session |
| 150 | +- **Providers**: Factory patterns and lazy initialization |
| 151 | +- **Interceptors**: AOP for cross-cutting concerns |
| 152 | +- **Multibindings**: Sets and maps of implementations |
| 153 | +- **Conditional Bindings**: Environment-specific configuration |
| 154 | + |
| 155 | +### Software Architecture Patterns |
| 156 | +- **Layered Architecture**: Presentation, business, data |
| 157 | +- **Repository Pattern**: Data access abstraction |
| 158 | +- **Service Layer**: Business logic coordination |
| 159 | +- **Factory Pattern**: Object creation strategies |
| 160 | +- **Strategy Pattern**: Interchangeable algorithms |
| 161 | +- **Observer Pattern**: Event-driven programming |
| 162 | +- **Decorator Pattern**: Behavior enhancement |
| 163 | + |
| 164 | +## 💡 Tips for Success |
| 165 | + |
| 166 | +1. **Run the Code**: Don't just read - execute the examples |
| 167 | +2. **Experiment**: Modify examples to see different behaviors |
| 168 | +3. **Ask Questions**: Check issues or discussions for help |
| 169 | +4. **Practice**: Build your own examples using the patterns |
| 170 | +5. **Review**: Come back to concepts as you gain experience |
| 171 | + |
| 172 | +## 🤝 Contributing |
| 173 | + |
| 174 | +Found an error or want to improve the tutorial? |
| 175 | +- Open an issue on GitHub |
| 176 | +- Submit a pull request |
| 177 | +- Share your own examples |
| 178 | + |
| 179 | +## 📚 Additional Resources |
| 180 | + |
| 181 | +- [Ray.Di Documentation](../manuals/1.0/en/) |
| 182 | +- [Ray.Di API Reference](https://github.com/ray-di/Ray.Di) |
| 183 | +- [Dependency Injection in PHP](https://www.php-di.org/doc/) |
| 184 | +- [Design Patterns in PHP](https://designpatternsphp.readthedocs.io/) |
| 185 | + |
| 186 | +--- |
| 187 | + |
| 188 | +**Ready to master Ray.Di?** Choose your starting point above and begin your journey to better software architecture! |
0 commit comments